Set up environment

source('~/Experiments/AP/stats/init_renv.R')
## Loading required package: Matrix
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
## 
## Attaching package: 'tidyr'
## The following object is masked from 'package:Matrix':
## 
##     expand
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
## Visit http://strengejacke.de/sjPlot for package-vignettes.
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
# plotting stuff
theme_set(theme_classic(base_size = 22))
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
library(RColorBrewer)

library(boot)
## 
## Attaching package: 'boot'
## The following object is masked from 'package:car':
## 
##     logit
zscore <- function(vec){(vec-mean(vec))/sd(vec)}

# run trial-wise mediation? (takes a long time - only do first time)
run_mediation = FALSE

0) Manipulation checks

00) Compare CTRU vs. Salimetrics assay on independent set of 49 samples (Salimetrics ran these using data from Gotlib lab)

dcort_salcompare = read.csv('/Volumes/group/awagner/sgagnon/AP/data/cortisol/salimetrics_comparison_n49samples.csv')
dim(dcort_salcompare)
## [1] 49  2
# correlation between assays
res_cor = cor.test(dcort_salcompare$lnSal_CORt_Mean, 
         y = dcort_salcompare$lnSAL_IBL_mean)
res_cor
## 
##  Pearson's product-moment correlation
## 
## data:  dcort_salcompare$lnSal_CORt_Mean and dcort_salcompare$lnSAL_IBL_mean
## t = 28.624, df = 47, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.9514994 0.9844757
## sample estimates:
##       cor 
## 0.9724964
cat('R^2: ', (res_cor$estimate)^2)
## R^2:  0.9457493
# mean of assays
dcort_salcompare %>% summarise_all(funs(mean, sd))
##   lnSal_CORt_Mean_mean lnSAL_IBL_mean_mean lnSal_CORt_Mean_sd
## 1            -2.639796           -2.540204           1.043768
##   lnSAL_IBL_mean_sd
## 1          1.072183
# compare means
bartlett.test(value ~ key, dcort_salcompare %>% gather())
## 
##  Bartlett test of homogeneity of variances
## 
## data:  value by key
## Bartlett's K-squared = 0.034268, df = 1, p-value = 0.8531
t.test(dcort_salcompare$lnSal_CORt_Mean,
       dcort_salcompare$lnSAL_IBL_mean, 
       var.equal=TRUE, paired = TRUE)
## 
##  Paired t-test
## 
## data:  dcort_salcompare$lnSal_CORt_Mean and dcort_salcompare$lnSAL_IBL_mean
## t = -2.7916, df = 48, p-value = 0.007507
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.17132349 -0.02786019
## sample estimates:
## mean of the differences 
##             -0.09959184
t.test(value ~ key, dcort_salcompare %>% gather(), 
       var.equal=TRUE, paired = TRUE)
## 
##  Paired t-test
## 
## data:  value by key
## t = -2.7916, df = 48, p-value = 0.007507
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.17132349 -0.02786019
## sample estimates:
## mean of the differences 
##             -0.09959184

0a) Cortisol

dcort = read.csv('/Volumes/group/awagner/sgagnon/AP/data/cortisol/combined_cort_results.csv')
head(dcort)
##   X Sample assay   cv   mean subid   group study log.ug.dL.  day
## 1 0     S1   IBL  6.3 0.2327 ap100 control  fmri  -1.624525 Day1
## 2 1     S2   IBL  4.0 0.1451 ap100 control  fmri  -2.068512 Day1
## 3 2     T1   IBL  1.9 0.1218 ap100 control  fmri  -2.233052 Day2
## 4 3     T2   IBL 10.8 0.0632 ap100 control  fmri  -2.849764 Day2
## 5 4     T3   IBL  5.5 0.1655 ap100 control  fmri  -1.944857 Day2
## 6 5     S1   IBL  3.3 0.0972 ap101 control  fmri  -2.445125 Day1
dcort %>% filter(log.ug.dL. > 0) # all neg
##  [1] X          Sample     assay      cv         mean       subid     
##  [7] group      study      log.ug.dL. day       
## <0 rows> (or 0-length row.names)
# calculate %change relative to baselines
dcort_change = dcort %>% 
  dplyr::select(subid, group, Sample, log.ug.dL., assay) %>% 
  spread(key = Sample, value=log.ug.dL.) %>%
  mutate(day1_change = (S2 - S1)/abs(S1) * 100,
         day2_change1 = (T2 - T1)/abs(T1) * 100,
         day2_change2 = (T3 - T1)/abs(T1) * 100,
         day2_avgchange = (day2_change1 + day2_change2)/2)
dcort_change
##    subid   group       assay         S1         S2         T1         T2
## 1  ap100 control         IBL -1.6245249 -2.0685122 -2.2330524 -2.8497639
## 2  ap101 control         IBL -2.4451255 -2.5756318 -2.0101161 -2.3110621
## 3  ap102 control         IBL -2.2454824 -2.3220268 -2.2246012 -2.2846048
## 4  ap103 control         IBL -0.7916171 -0.8377518 -1.1613053 -0.8806980
## 5  ap104 control         IBL -1.8622621 -2.3610006 -2.6875986 -2.6305379
## 6  ap105 control         IBL -1.7432022 -2.2952634 -1.8437190 -1.9262983
## 7  ap106 control         IBL -1.8669555 -1.5814941 -1.2402958 -1.6229105
## 8  ap107 control         IBL -1.2459496 -1.7010788 -1.6628639 -2.0217552
## 9  ap108 control         IBL -2.3495746 -2.9838212 -1.7028334 -2.1328566
## 10 ap109 control         IBL -1.0479879 -1.7844245 -0.9211022 -2.0242241
## 11 ap110 control         IBL -1.4195487 -1.7969580 -1.5016348 -2.2927930
## 12 ap111 control         IBL -1.9037394 -2.2764873 -1.2870716 -1.9831114
## 13 ap113 control         IBL -1.3739025 -1.7519507 -2.3161068 -1.7887441
## 14 ap114 control         IBL -1.8295453 -1.8945422 -2.4174905 -2.5195601
## 15 ap115 control         IBL -1.8140984 -2.0322928 -1.3885587 -1.9914300
## 16 ap116 control Salimetrics -1.1647521 -1.3356012 -1.3704210 -1.0671136
## 17 ap117 control Salimetrics -1.8971200 -1.5186835 -1.4146938 -1.7429693
## 18 ap118 control Salimetrics -0.7916171 -1.4481698 -1.4229583 -1.9519282
## 19 ap119 control Salimetrics -2.3968958 -2.6036902 -2.2633644 -2.8824036
## 20 ap120 control Salimetrics -2.0874737 -2.1715568 -1.4961092 -1.5847453
## 21 ap121 control Salimetrics -1.7897615 -1.7092582 -2.7030627 -1.9241487
## 22 ap122 control Salimetrics -2.0249534 -2.7181005 -1.7544637 -2.0249534
## 23 ap150  stress         IBL -1.0075262 -1.5333556 -1.3455587 -1.1150783
## 24 ap151  stress         IBL -2.2034257 -1.6387707 -2.3495746 -1.9687286
## 25 ap152  stress         IBL -1.4858183 -1.7993876 -2.9676652 -3.0467773
## 26 ap153  stress         IBL -2.2318955 -2.1718076 -1.5159207 -2.0001241
## 27 ap154  stress         IBL -1.9488413 -2.0562833 -2.1307777 -2.6376322
## 28 ap155  stress         IBL -1.7054713 -1.7955033 -1.9935212 -1.6653919
## 29 ap156  stress         IBL -1.5256880 -1.9174303 -1.2170978 -2.0354147
## 30 ap157  stress         IBL -1.5931423 -1.5019893 -2.1567443 -2.3979742
## 31 ap158 control Salimetrics -0.7916171 -0.7916171 -0.7916171 -1.5994876
## 32 ap159  stress         IBL -2.3897325 -2.0543669 -2.0285601 -1.6478369
## 33 ap160  stress         IBL -2.2265153 -1.9257415 -1.6815625 -2.1517764
## 34 ap161  stress         IBL -1.9316035 -1.8514009 -2.2462647 -1.7829890
## 35 ap162  stress         IBL -2.2652393 -1.4458994 -2.6690087 -1.9911317
## 36 ap163  stress         IBL -2.2989813 -2.7337744 -2.4937485 -2.1878514
## 37 ap164  stress Salimetrics -1.7203695 -2.1541651 -0.8051967 -1.1147417
## 38 ap165  stress         IBL -1.2222183 -1.8178123 -1.7758443 -2.1937541
## 39 ap166  stress Salimetrics -1.4653376 -1.3356012 -2.2349264 -1.3783262
## 40 ap167  stress Salimetrics -1.1711830 -1.6607312 -1.5511690 -1.4312917
## 41 ap168  stress Salimetrics -2.4651040 -2.7030627 -2.4079456 -2.9565116
## 42 ap169  stress Salimetrics -2.4304185 -2.5133061 -2.6310892 -2.2164074
## 43 ap170  stress Salimetrics -1.5994876 -1.2909842 -1.4524342 -1.5371173
## 44 ap171  stress Salimetrics -1.7037486 -1.8388511 -1.8838748 -2.1037342
## 45 ap172  stress Salimetrics -0.7916171 -1.1679624 -1.5371173 -0.7916171
## 46 ap173  stress Salimetrics -2.2256241 -1.9105430 -2.0635682 -2.4534080
## 47 ap174  stress Salimetrics -1.9877744 -2.4889147 -2.4304185 -2.9187712
##            T3 day1_change day2_change1  day2_change2 day2_avgchange
## 1  -1.9448570  -27.330286   -27.617421   12.90589444      -7.355763
## 2  -2.4100078   -5.337405   -14.971572  -19.89396051     -17.432766
## 3  -2.1061833   -3.408819    -2.697273    5.32310656       1.312917
## 4  -1.0953175   -5.827912    24.163094    5.68221124      14.922653
## 5  -2.5569301  -26.781330     2.123113    4.86190517       3.492509
## 6  -1.8627824  -31.669377    -4.478951   -1.03396507      -2.756458
## 7  -1.8437190   15.290212   -30.848662  -48.65155378     -39.750108
## 8  -2.4422287  -36.528706   -21.582724  -46.86882757     -34.225776
## 9  -3.0116751  -26.994105   -25.253397  -76.86258346     -51.057990
## 10 -2.3495746  -70.271479  -119.761080 -155.08294897    -137.422014
## 11 -2.3583515  -26.586568   -52.686462  -57.05226896     -54.869365
## 12 -2.3672111  -19.579776   -54.079334  -83.92224989     -69.000792
## 13 -2.5174689  -27.516372    22.769360   -8.69398688       7.037686
## 14 -2.0492755   -3.552623    -4.222132   15.23128878       5.504579
## 15 -2.9786892  -12.027705   -43.417060 -114.51662675     -78.966844
## 16 -1.3470736  -14.668285    22.132424    1.70366360      11.918044
## 17 -0.9545119   19.947944   -23.204701   32.52872667       4.662013
## 18 -1.1679624  -82.938166   -37.173954   17.92012953      -9.626912
## 19 -3.2441936   -8.627593   -27.350400  -43.33501321     -35.342707
## 20 -2.4418472   -4.027984    -5.924439  -63.21316091     -34.568800
## 21 -2.1455813    4.497986    28.815980   20.62406187      24.720021
## 22 -2.3538784  -34.230279   -15.417228  -34.16512455     -24.791176
## 23 -1.0852492  -52.190137    17.128972   19.34582775      18.237400
## 24 -1.6582468   25.626235    16.209145   29.42352925      22.816337
## 25 -2.2211657  -21.104144    -2.665802   25.15443883      11.244318
## 26 -1.9105051    2.692237   -31.941204  -26.02935438     -28.985279
## 27 -1.5069666   -5.513124   -23.787300   29.27621844       2.744459
## 28 -1.1238116   -5.279007    16.459785   43.62680654      30.043296
## 29 -2.1412184  -25.676433   -67.235089  -75.92820766     -71.581648
## 30 -2.1098994    5.721588   -11.184909    2.17201928      -4.506445
## 31 -1.9732813    0.000000  -102.053192 -149.27220433    -125.662698
## 32 -1.8612222   14.033605    18.768149    8.24909772      13.508624
## 33 -1.6971430   13.508721   -27.962911   -0.92654700     -14.444729
## 34 -1.9626313    4.152126    20.624270   12.62689275      16.625581
## 35 -2.6400090   36.170123    25.398083    1.08653558      13.242309
## 36 -2.4927306  -18.912423    12.266556    0.04081674       6.153686
## 37 -2.1455813  -25.215259   -38.443401 -166.46673860    -102.455070
## 38 -2.5385934  -48.730574   -23.533019  -42.95134544     -33.242182
## 39 -0.7916171    8.853682    38.327895   64.57972556      51.453810
## 40 -1.6194882  -41.799465     7.728189   -4.40437140       1.661909
## 41 -2.7488722   -9.653087   -22.781493  -14.15840066     -18.469947
## 42 -1.8515095   -3.410428    15.760840   29.62954271      22.695192
## 43 -1.7602608   19.287640    -5.830425  -21.19384453     -13.512135
## 44 -2.3434071   -7.929720   -11.670599  -24.39293416     -18.031767
## 45 -1.5232602  -47.541330    48.499890    0.90149497      24.700692
## 46 -1.4828053   14.156975   -18.891539   28.14362681       4.626044
## 47 -3.1010928  -25.211127   -20.093361  -27.59501438     -23.844188
contrasts(dcort_change$group) = c(-1,1); contrasts(dcort_change$group)
##         [,1]
## control   -1
## stress     1
contrasts(dcort_change$assay) = c(-1,1); contrasts(dcort_change$assay) 
##             [,1]
## IBL           -1
## Salimetrics    1
dcort_change %>% group_by(subid, group) %>% summarise(n())%>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    23
## 2  stress    24
# day 1
summary(lm(day1_change ~ group + assay, data=dcort_change))
## 
## Call:
## lm(formula = day1_change ~ group + assay, data = dcort_change)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -63.805 -13.341   2.472  15.018  43.922 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.4423     3.6586  -3.674 0.000644 ***
## group1        5.2944     3.5642   1.485 0.144561    
## assay1       -0.3965     3.6652  -0.108 0.914355    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 24.37 on 44 degrees of freedom
## Multiple R-squared:  0.04775,    Adjusted R-squared:  0.004469 
## F-statistic: 1.103 on 2 and 44 DF,  p-value: 0.3408
# day 2
summary(lm(day2_avgchange ~ group + assay, data=dcort_change))
## 
## Call:
## lm(formula = day2_avgchange ~ group + assay, data = dcort_change)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -109.09  -14.70    8.18   26.45   55.01 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -15.9413     5.7954  -2.751   0.0086 **
## group1       12.2436     5.6459   2.169   0.0356 * 
## assay1        0.1438     5.8059   0.025   0.9804   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 38.6 on 44 degrees of freedom
## Multiple R-squared:  0.09715,    Adjusted R-squared:  0.05611 
## F-statistic: 2.367 on 2 and 44 DF,  p-value: 0.1056
summary(lm(day2_change1 ~ group + assay, data=dcort_change))
## 
## Call:
## lm(formula = day2_change1 ~ group + assay, data = dcort_change)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -96.226 -19.242   1.691  20.827  49.286 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  -12.160      4.858  -2.503   0.0161 *
## group1         9.589      4.732   2.026   0.0488 *
## assay1         1.785      4.867   0.367   0.7155  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 32.36 on 44 degrees of freedom
## Multiple R-squared:  0.0903, Adjusted R-squared:  0.04895 
## F-statistic: 2.184 on 2 and 44 DF,  p-value: 0.1247
summary(lm(day2_change2 ~ group + assay, data=dcort_change))
## 
## Call:
## lm(formula = day2_change2 ~ group + assay, data = dcort_change)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -160.145  -19.672    5.498   35.209   70.902 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  -19.722      7.551  -2.612   0.0123 *
## group1        14.898      7.357   2.025   0.0489 *
## assay1        -1.498      7.565  -0.198   0.8440  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 50.3 on 44 degrees of freedom
## Multiple R-squared:  0.08532,    Adjusted R-squared:  0.04374 
## F-statistic: 2.052 on 2 and 44 DF,  p-value: 0.1406
# day 2: time * group interaction
dcort_combined = dcort_change %>% 
  dplyr::select(subid, group, assay, day2_change1, day2_change2) %>%
  gather(time, cort, day2_change1:day2_change2) %>%
  mutate(time = factor(time))
contrasts(dcort_combined$time) = c(-1,1); contrasts(dcort_combined$time)
##              [,1]
## day2_change1   -1
## day2_change2    1
summary(lmer(cort ~ time * group + assay + (1|subid), data=dcort_combined))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: cort ~ time * group + assay + (1 | subid)
##    Data: dcort_combined
## 
## REML criterion at convergence: 914.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4085 -0.3423 -0.0412  0.4983  1.7982 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 1195.7   34.58   
##  Residual              588.6   24.26   
## Number of obs: 94, groups:  subid, 47
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)   
## (Intercept)  -15.9413     5.7954  44.0000  -2.751   0.0086 **
## time1         -3.3944     2.5028  45.0000  -1.356   0.1818   
## group1        12.2436     5.6459  44.0000   2.169   0.0356 * 
## assay1         0.1438     5.8059  44.0000   0.025   0.9804   
## time1:group1   2.5414     2.5028  45.0000   1.015   0.3153   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) time1  group1 assay1
## time1        0.000                     
## group1      -0.037  0.000              
## assay1       0.236  0.000 -0.071       
## time1:grop1  0.000 -0.021  0.000  0.000
# day * group interaction
dcort_combined = dcort_change %>% 
  dplyr::select(subid, group, assay, day1_change, day2_avgchange) %>%
  gather(day, cort, day1_change:day2_avgchange) %>%
  mutate(day = factor(day))

contrasts(dcort_combined$day) = c(-1,1)
contrasts(dcort_combined$group)
##         [,1]
## control   -1
## stress     1
summary(lmer(cort ~ day * group + assay + (1|subid), data=dcort_combined))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: cort ~ day * group + assay + (1 | subid)
##    Data: dcort_combined
## 
## REML criterion at convergence: 890.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.9287 -0.4603  0.1441  0.5752  1.4796 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 240.3    15.50   
##  Residual             792.6    28.15   
## Number of obs: 94, groups:  subid, 47
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept) -14.6918     3.7883  44.0000  -3.878 0.000348 ***
## day1         -1.3131     2.9045  45.0000  -0.452 0.653368    
## group1        8.7690     3.6906  44.0000   2.376 0.021918 *  
## assay1       -0.1263     3.7951  44.0000  -0.033 0.973597    
## day1:group1   3.4932     2.9045  45.0000   1.203 0.235387    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) day1   group1 assay1
## day1         0.000                     
## group1      -0.037  0.000              
## assay1       0.236  0.000 -0.071       
## day1:group1  0.000 -0.021  0.000  0.000
contrasts(dcort_combined$day) = c(0,1); contrasts(dcort_combined$day)
##                [,1]
## day1_change       0
## day2_avgchange    1
summary(lmer(cort ~ day * group + assay+ (1|subid), data=dcort_combined))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: cort ~ day * group + assay + (1 | subid)
##    Data: dcort_combined
## 
## REML criterion at convergence: 887.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.9287 -0.4603  0.1441  0.5752  1.4796 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 240.3    15.50   
##  Residual             792.6    28.15   
## Number of obs: 94, groups:  subid, 47
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)   
## (Intercept) -13.3787     4.7736  82.9200  -2.803  0.00631 **
## day1         -2.6263     5.8090  45.0000  -0.452  0.65337   
## group1        5.2758     4.6964  83.9100   1.123  0.26449   
## assay1       -0.1263     3.7951  44.0000  -0.033  0.97360   
## day1:group1   6.9864     5.8090  45.0000   1.203  0.23539   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) day1   group1 assay1
## day1        -0.608                     
## group1      -0.031  0.013              
## assay1       0.187  0.000 -0.056       
## day1:group1  0.013 -0.021 -0.618  0.000
contrasts(dcort_combined$day) = c(1,0); contrasts(dcort_combined$day)
##                [,1]
## day1_change       1
## day2_avgchange    0
summary(lmer(cort ~ day * group + assay + (1|subid), data=dcort_combined))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: cort ~ day * group + assay + (1 | subid)
##    Data: dcort_combined
## 
## REML criterion at convergence: 887.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.9287 -0.4603  0.1441  0.5752  1.4796 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 240.3    15.50   
##  Residual             792.6    28.15   
## Number of obs: 94, groups:  subid, 47
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)   
## (Intercept) -16.0049     4.7736  82.9200  -3.353  0.00121 **
## day1          2.6263     5.8090  45.0000   0.452  0.65337   
## group1       12.2622     4.6964  83.9100   2.611  0.01069 * 
## assay1       -0.1263     3.7951  44.0000  -0.033  0.97360   
## day1:group1  -6.9864     5.8090  45.0000  -1.203  0.23539   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) day1   group1 assay1
## day1        -0.608                     
## group1      -0.031  0.013              
## assay1       0.187  0.000 -0.056       
## day1:group1  0.013 -0.021 -0.618  0.000
# check out raw levels at T2 and T3
hist(dcort_change$T3)

summary(lm(T2 ~ group + assay, data=dcort_change))
## 
## Call:
## lm(formula = T2 ~ group + assay, data = dcort_change)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.08512 -0.23595  0.04727  0.28758  1.19079 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.9714440  0.0807888 -24.402   <2e-16 ***
## group1      -0.0003406  0.0787055  -0.004    0.997    
## assay1       0.1003888  0.0809356   1.240    0.221    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5381 on 44 degrees of freedom
## Multiple R-squared:  0.03393,    Adjusted R-squared:  -0.009979 
## F-statistic: 0.7727 on 2 and 44 DF,  p-value: 0.4679
summary(lm(T3 ~ group + assay, data=dcort_change))
## 
## Call:
## lm(formula = T3 ~ group + assay, data = dcort_change)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.25186 -0.30628 -0.00228  0.32761  1.10847 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.02524    0.08654 -23.402   <2e-16 ***
## group1       0.10688    0.08431   1.268    0.212    
## assay1       0.06913    0.08670   0.797    0.430    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.5764 on 44 degrees of freedom
## Multiple R-squared:  0.05168,    Adjusted R-squared:  0.008573 
## F-statistic: 1.199 on 2 and 44 DF,  p-value: 0.3112

Plot

d_cort = read.csv('/Volumes/group/awagner/sgagnon/AP/data/cortisol/cort_percentchange_t1-2_testbaseline.csv')
str(d_cort)
## 'data.frame':    141 obs. of  6 variables:
##  $ X         : int  0 1 2 3 4 5 6 7 8 9 ...
##  $ subid     : Factor w/ 47 levels "ap100","ap101",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ group     : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ assay     : Factor w/ 2 levels "IBL","Salimetrics": 1 1 1 1 1 1 1 1 1 1 ...
##  $ Sample    : Factor w/ 3 levels "T1","T2","T3": 1 1 1 1 1 1 1 1 1 1 ...
##  $ log.ug.dL.: num  0 0 0 0 0 0 0 0 0 0 ...
dfwc = d_cort %>% group_by(group, Sample) %>%
  summarise(value = mean(log.ug.dL.),
            se = std.error(log.ug.dL.),
            n()) 
dfwc
## Source: local data frame [6 x 5]
## Groups: group [?]
## 
## # A tibble: 6 x 5
##     group Sample      value        se `n()`
##    <fctr> <fctr>      <dbl>     <dbl> <int>
## 1 control     T1   0.000000  0.000000    23
## 2 control     T2 -22.292870  7.618383    23
## 3 control     T3 -34.164499 11.173649    23
## 4  stress     T1   0.000000  0.000000    24
## 5  stress     T2  -2.868720  5.522414    24
## 6  stress     T3  -4.574591  9.347423    24
# dfwc
p3 = ggplot(dfwc, aes(x=Sample, y=value, group=group, color=group)) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=value-se, ymax=value+se), 
                  size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('% Change in cortisol\n(relative to T1)')+
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  xlab('Sample') +
  theme(legend.title=element_blank())

ggsave('~/Experiments/AP/figs/AP_behav_cort.jpeg', p3, dpi=300, width=5, height=4)
p3

0b) Questionnaires:

Do ratings on in-scanner valence questionnaires differ between groups?

##   subid BAS.D BAS.F BAS.W      BIS  SMM TraitAnx        group run
## 1 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   1
## 2 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   1
## 3 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   1
## 4 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   2
## 5 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   2
## 6 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   2
##   shockCond subScaleName adjustedRating  respRT remove good_math
## 1      safe      Arousal            1.0 3.45640     NA         5
## 2      safe     Negative            1.5 3.91895     NA         5
## 3      safe     Positive            2.5 3.09475     NA         5
## 4    threat      Arousal            1.0 1.07310     NA         5
## 5    threat     Negative            2.5 1.32142     NA         5
## 6    threat     Positive            2.5 3.32340     NA         5
##   important_math anxious happy safe stressed life_stress sleep modality
## 1              6       3     2    3        3           4   4.5     fmri
## 2              6       3     2    3        3           4   4.5     fmri
## 3              6       3     2    3        3           4   4.5     fmri
## 4              6       3     2    3        3           4   4.5     fmri
## 5              6       3     2    3        3           4   4.5     fmri
## 6              6       3     2    3        3           4   4.5     fmri
##   stress_group
## 1      control
## 2      control
## 3      control
## 4      control
## 5      control
## 6      control
##     subid BAS.D BAS.F BAS.W      BIS   SMM TraitAnx        group run
## 1   ap100  3.50  3.75   3.2 3.714286 2.750     2.80 control-fmri   1
## 2   ap100  3.50  3.75   3.2 3.714286 2.750     2.80 control-fmri   1
## 3   ap100  3.50  3.75   3.2 3.714286 2.750     2.80 control-fmri   2
## 4   ap100  3.50  3.75   3.2 3.714286 2.750     2.80 control-fmri   2
## 5   ap100  3.50  3.75   3.2 3.714286 2.750     2.80 control-fmri   4
## 6   ap100  3.50  3.75   3.2 3.714286 2.750     2.80 control-fmri   4
## 7   ap100  3.50  3.75   3.2 3.714286 2.750     2.80 control-fmri   5
## 8   ap100  3.50  3.75   3.2 3.714286 2.750     2.80 control-fmri   5
## 9   ap100  3.50  3.75   3.2 3.714286 2.750     2.80 control-fmri   6
## 10  ap100  3.50  3.75   3.2 3.714286 2.750     2.80 control-fmri   6
## 11  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   1
## 12  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   1
## 13  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   2
## 14  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   2
## 15  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   3
## 16  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   3
## 17  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   4
## 18  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   4
## 19  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   5
## 20  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   5
## 21  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   6
## 22  ap101  3.75  2.00   3.6 3.571429 3.375     1.95 control-fmri   6
## 23  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   1
## 24  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   1
## 25  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   2
## 26  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   2
## 27  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   3
## 28  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   3
## 29  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   4
## 30  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   4
## 31  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   5
## 32  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   5
## 33  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   6
## 34  ap102  3.50  3.75   3.8 2.714286 1.750     2.10 control-fmri   6
## 35  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   1
## 36  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   1
## 37  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   2
## 38  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   2
## 39  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   3
## 40  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   3
## 41  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   4
## 42  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   4
## 43  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   5
## 44  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   5
## 45  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   6
## 46  ap103  2.75  3.25   3.4 2.714286 2.250     1.50 control-fmri   6
## 47  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   1
## 48  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   1
## 49  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   2
## 50  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   2
## 51  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   3
## 52  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   3
## 53  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   4
## 54  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   4
## 55  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   5
## 56  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   5
## 57  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   6
## 58  ap104  2.75  2.75   3.8 3.142857 3.125     2.85 control-fmri   6
## 59  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   1
## 60  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   1
## 61  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   2
## 62  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   2
## 63  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   3
## 64  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   3
## 65  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   4
## 66  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   4
## 67  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   5
## 68  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   5
## 69  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   6
## 70  ap105  2.75  3.00   3.8 3.285714 3.125     2.05 control-fmri   6
## 71  ap106  2.75  2.75   3.0 2.714286 3.125     2.20 control-fmri   2
## 72  ap106  2.75  2.75   3.0 2.714286 3.125     2.20 control-fmri   2
## 73  ap106  2.75  2.75   3.0 2.714286 3.125     2.20 control-fmri   3
## 74  ap106  2.75  2.75   3.0 2.714286 3.125     2.20 control-fmri   3
## 75  ap106  2.75  2.75   3.0 2.714286 3.125     2.20 control-fmri   4
## 76  ap106  2.75  2.75   3.0 2.714286 3.125     2.20 control-fmri   4
## 77  ap106  2.75  2.75   3.0 2.714286 3.125     2.20 control-fmri   5
## 78  ap106  2.75  2.75   3.0 2.714286 3.125     2.20 control-fmri   5
## 79  ap106  2.75  2.75   3.0 2.714286 3.125     2.20 control-fmri   6
## 80  ap106  2.75  2.75   3.0 2.714286 3.125     2.20 control-fmri   6
## 81  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   1
## 82  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   1
## 83  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   2
## 84  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   2
## 85  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   3
## 86  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   3
## 87  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   4
## 88  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   4
## 89  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   5
## 90  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   5
## 91  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   6
## 92  ap107  2.50  3.25   3.6 3.000000 2.375     3.10 control-fmri   6
## 93  ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   1
## 94  ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   1
## 95  ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   2
## 96  ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   2
## 97  ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   3
## 98  ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   3
## 99  ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   4
## 100 ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   4
## 101 ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   5
## 102 ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   5
## 103 ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   6
## 104 ap108  2.25  2.50   3.0 3.142857 3.125     1.70 control-fmri   6
## 105 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   1
## 106 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   1
## 107 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   2
## 108 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   2
## 109 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   3
## 110 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   3
## 111 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   4
## 112 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   4
## 113 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   5
## 114 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   5
## 115 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   6
## 116 ap109  4.00  3.75   3.8 2.571429 1.500     2.05 control-fmri   6
## 117 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   1
## 118 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   1
## 119 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   2
## 120 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   2
## 121 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   3
## 122 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   3
## 123 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   4
## 124 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   4
## 125 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   5
## 126 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   5
## 127 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   6
## 128 ap110  3.00  2.25   3.4 2.285714 2.500     1.55 control-fmri   6
## 129 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   1
## 130 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   1
## 131 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   2
## 132 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   2
## 133 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   3
## 134 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   3
## 135 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   4
## 136 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   4
## 137 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   5
## 138 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   5
## 139 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   6
## 140 ap111  2.75  3.25   3.2 2.714286 2.375     2.50 control-fmri   6
## 141 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   1
## 142 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   1
## 143 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   2
## 144 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   2
## 145 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   3
## 146 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   3
## 147 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   4
## 148 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   4
## 149 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   5
## 150 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   5
## 151 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   6
## 152 ap113  3.25  3.50   3.6 3.000000 3.250     2.95 control-fmri   6
## 153 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   1
## 154 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   1
## 155 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   2
## 156 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   2
## 157 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   3
## 158 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   3
## 159 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   4
## 160 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   4
## 161 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   5
## 162 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   5
## 163 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   6
## 164 ap114  3.25  3.50   4.0 2.285714 3.750     1.70 control-fmri   6
## 165 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   1
## 166 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   1
## 167 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   2
## 168 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   2
## 169 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   3
## 170 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   3
## 171 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   4
## 172 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   4
## 173 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   5
## 174 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   5
## 175 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   6
## 176 ap115  4.00  3.50   4.0 2.428571 3.000     1.65 control-fmri   6
## 177 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   1
## 178 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   1
## 179 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   2
## 180 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   2
## 181 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   3
## 182 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   3
## 183 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   4
## 184 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   4
## 185 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   5
## 186 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   5
## 187 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   6
## 188 ap116  3.00  3.25   3.8 3.428571 3.500     1.95 control-fmri   6
## 189 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   1
## 190 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   1
## 191 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   2
## 192 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   2
## 193 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   3
## 194 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   3
## 195 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   4
## 196 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   4
## 197 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   5
## 198 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   5
## 199 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   6
## 200 ap117  3.75  4.00   4.0 2.428571 3.625     2.20 control-fmri   6
## 201 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   1
## 202 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   1
## 203 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   2
## 204 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   2
## 205 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   3
## 206 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   3
## 207 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   4
## 208 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   4
## 209 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   5
## 210 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   5
## 211 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   6
## 212 ap118  3.00  3.50   3.2 2.142857 2.875     2.05 control-fmri   6
## 213 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   1
## 214 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   1
## 215 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   2
## 216 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   2
## 217 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   3
## 218 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   3
## 219 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   4
## 220 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   4
## 221 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   5
## 222 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   5
## 223 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   6
## 224 ap119  2.75  2.00   3.0 2.857143 3.250     1.80 control-fmri   6
## 225 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   1
## 226 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   1
## 227 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   2
## 228 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   2
## 229 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   3
## 230 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   3
## 231 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   4
## 232 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   4
## 233 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   5
## 234 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   5
## 235 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   6
## 236 ap120  3.50  3.50   3.8 2.142857 2.875     1.55 control-fmri   6
## 237 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   1
## 238 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   1
## 239 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   2
## 240 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   2
## 241 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   3
## 242 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   3
## 243 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   4
## 244 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   4
## 245 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   5
## 246 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   5
## 247 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   6
## 248 ap121  4.00  3.75   3.8 2.142857 3.375     1.80 control-fmri   6
## 249 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   1
## 250 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   1
## 251 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   2
## 252 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   2
## 253 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   3
## 254 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   3
## 255 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   4
## 256 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   4
## 257 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   5
## 258 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   5
## 259 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   6
## 260 ap122  2.50  2.50   3.6 3.571429 3.375     2.55 control-fmri   6
## 261 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   1
## 262 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   1
## 263 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   2
## 264 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   2
## 265 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   3
## 266 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   3
## 267 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   4
## 268 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   4
## 269 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   5
## 270 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   5
## 271 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   6
## 272 ap150  2.50  3.00   3.0 2.571429 2.125     2.60  stress-fmri   6
## 273 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   1
## 274 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   1
## 275 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   2
## 276 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   2
## 277 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   3
## 278 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   3
## 279 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   4
## 280 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   4
## 281 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   5
## 282 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   5
## 283 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   6
## 284 ap151  2.25  2.50   2.6 2.857143 3.375     2.40  stress-fmri   6
## 285 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   1
## 286 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   1
## 287 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   2
## 288 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   2
## 289 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   3
## 290 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   3
## 291 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   4
## 292 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   4
## 293 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   5
## 294 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   5
## 295 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   6
## 296 ap152  3.25  3.00   3.2 2.285714 3.500     1.95  stress-fmri   6
## 297 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   1
## 298 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   1
## 299 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   2
## 300 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   2
## 301 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   3
## 302 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   3
## 303 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   4
## 304 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   4
## 305 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   5
## 306 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   5
## 307 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   6
## 308 ap153  2.50  3.50   2.8 2.285714 2.000     1.55  stress-fmri   6
## 309 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   1
## 310 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   1
## 311 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   2
## 312 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   2
## 313 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   3
## 314 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   3
## 315 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   4
## 316 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   4
## 317 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   5
## 318 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   5
## 319 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   6
## 320 ap154  2.25  2.50   3.4 2.857143 3.750     1.85  stress-fmri   6
## 321 ap155  3.75  3.50   4.0 2.142857 3.625     1.30  stress-fmri   1
## 322 ap155  3.75  3.50   4.0 2.142857 3.625     1.30  stress-fmri   1
## 323 ap155  3.75  3.50   4.0 2.142857 3.625     1.30  stress-fmri   2
## 324 ap155  3.75  3.50   4.0 2.142857 3.625     1.30  stress-fmri   2
## 325 ap155  3.75  3.50   4.0 2.142857 3.625     1.30  stress-fmri   3
## 326 ap155  3.75  3.50   4.0 2.142857 3.625     1.30  stress-fmri   3
## 327 ap155  3.75  3.50   4.0 2.142857 3.625     1.30  stress-fmri   4
## 328 ap155  3.75  3.50   4.0 2.142857 3.625     1.30  stress-fmri   4
## 329 ap155  3.75  3.50   4.0 2.142857 3.625     1.30  stress-fmri   5
## 330 ap155  3.75  3.50   4.0 2.142857 3.625     1.30  stress-fmri   5
## 331 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   1
## 332 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   1
## 333 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   2
## 334 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   2
## 335 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   3
## 336 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   3
## 337 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   4
## 338 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   4
## 339 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   5
## 340 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   5
## 341 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   6
## 342 ap156  3.75  2.75   3.8 2.428571 3.750     1.55  stress-fmri   6
## 343 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   1
## 344 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   1
## 345 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   2
## 346 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   2
## 347 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   3
## 348 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   3
## 349 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   4
## 350 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   4
## 351 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   5
## 352 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   5
## 353 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   6
## 354 ap157  2.50  3.75   3.4 2.571429 2.500     1.40  stress-fmri   6
## 355 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   1
## 356 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   1
## 357 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   2
## 358 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   2
## 359 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   3
## 360 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   3
## 361 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   4
## 362 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   4
## 363 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   5
## 364 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   5
## 365 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   6
## 366 ap158  2.75  2.75   3.4 3.142857 3.375     1.50 control-fmri   6
## 367 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   1
## 368 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   1
## 369 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   2
## 370 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   2
## 371 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   3
## 372 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   3
## 373 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   4
## 374 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   4
## 375 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   5
## 376 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   5
## 377 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   6
## 378 ap159  3.50  3.00   4.0 3.571429 1.875     3.25  stress-fmri   6
## 379 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   1
## 380 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   1
## 381 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   2
## 382 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   2
## 383 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   3
## 384 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   3
## 385 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   4
## 386 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   4
## 387 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   5
## 388 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   5
## 389 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   6
## 390 ap160  3.00  3.25   3.8 3.571429 3.000     1.95  stress-fmri   6
## 391 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   1
## 392 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   1
## 393 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   2
## 394 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   2
## 395 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   3
## 396 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   3
## 397 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   4
## 398 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   4
## 399 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   5
## 400 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   5
## 401 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   6
## 402 ap161  3.00  3.25   4.0 3.571429 2.625     1.95  stress-fmri   6
## 403 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   1
## 404 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   1
## 405 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   2
## 406 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   2
## 407 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   3
## 408 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   3
## 409 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   4
## 410 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   4
## 411 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   5
## 412 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   5
## 413 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   6
## 414 ap162  3.00  2.75   3.4 3.000000 3.625     2.10  stress-fmri   6
## 415 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   1
## 416 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   1
## 417 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   2
## 418 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   2
## 419 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   3
## 420 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   3
## 421 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   4
## 422 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   4
## 423 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   5
## 424 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   5
## 425 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   6
## 426 ap163  2.50  3.00   3.4 2.857143 3.000     2.10  stress-fmri   6
## 427 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   1
## 428 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   1
## 429 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   2
## 430 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   2
## 431 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   3
## 432 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   3
## 433 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   4
## 434 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   4
## 435 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   5
## 436 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   5
## 437 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   6
## 438 ap164  4.00  4.00   3.4 3.285714 2.875     2.75  stress-fmri   6
## 439 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   1
## 440 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   1
## 441 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   2
## 442 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   2
## 443 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   3
## 444 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   3
## 445 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   4
## 446 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   4
## 447 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   5
## 448 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   5
## 449 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   6
## 450 ap165  3.75  2.50   3.8 3.857143 3.250     1.80  stress-fmri   6
## 451 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   1
## 452 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   1
## 453 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   2
## 454 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   2
## 455 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   3
## 456 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   3
## 457 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   4
## 458 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   4
## 459 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   5
## 460 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   5
## 461 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   6
## 462 ap166  4.00  3.75   3.8 2.285714 3.375     1.80  stress-fmri   6
## 463 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   1
## 464 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   1
## 465 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   2
## 466 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   2
## 467 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   3
## 468 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   3
## 469 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   4
## 470 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   4
## 471 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   5
## 472 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   5
## 473 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   6
## 474 ap167  3.25  3.75   3.8 2.571429 4.000     1.80  stress-fmri   6
## 475 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   1
## 476 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   1
## 477 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   2
## 478 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   2
## 479 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   3
## 480 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   3
## 481 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   4
## 482 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   4
## 483 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   5
## 484 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   5
## 485 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   6
## 486 ap168  3.50  4.00   3.8 3.142857 2.250     2.35  stress-fmri   6
## 487 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   1
## 488 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   1
## 489 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   2
## 490 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   2
## 491 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   3
## 492 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   3
## 493 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   4
## 494 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   4
## 495 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   5
## 496 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   5
## 497 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   6
## 498 ap169  3.25  3.75   3.4 2.571429 3.375     2.35  stress-fmri   6
## 499 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   1
## 500 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   1
## 501 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   2
## 502 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   2
## 503 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   3
## 504 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   3
## 505 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   4
## 506 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   4
## 507 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   5
## 508 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   5
## 509 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   6
## 510 ap170  3.75  2.50   4.0 3.428571 3.000     2.10  stress-fmri   6
## 511 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   1
## 512 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   1
## 513 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   2
## 514 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   2
## 515 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   3
## 516 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   3
## 517 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   4
## 518 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   4
## 519 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   5
## 520 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   5
## 521 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   6
## 522 ap171  3.25  3.00   3.0 2.571429 3.000     1.70  stress-fmri   6
## 523 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   1
## 524 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   1
## 525 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   2
## 526 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   2
## 527 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   3
## 528 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   3
## 529 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   4
## 530 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   4
## 531 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   5
## 532 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   5
## 533 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   6
## 534 ap172  3.00  3.00   3.2 3.571429 3.000     2.70  stress-fmri   6
## 535 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   1
## 536 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   1
## 537 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   2
## 538 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   2
## 539 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   3
## 540 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   3
## 541 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   4
## 542 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   4
## 543 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   5
## 544 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   5
## 545 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   6
## 546 ap173  3.00  3.75   3.6 2.714286 3.125     2.40  stress-fmri   6
## 547 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   1
## 548 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   1
## 549 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   2
## 550 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   2
## 551 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   3
## 552 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   3
## 553 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   4
## 554 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   4
## 555 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   5
## 556 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   5
## 557 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   6
## 558 ap174  3.25  3.25   3.6 3.000000 3.000     1.65  stress-fmri   6
##     shockCond subScaleName adjustedRating    respRT remove good_math
## 1        safe     Negative            1.5  3.918950     NA         5
## 2        safe     Positive            2.5  3.094750     NA         5
## 3      threat     Negative            2.5  1.321420     NA         5
## 4      threat     Positive            2.5  3.323400     NA         5
## 5      threat     Negative            2.0  3.216950     NA         5
## 6      threat     Positive            2.5  1.801150     NA         5
## 7        safe     Negative            2.5  3.536500     NA         5
## 8        safe     Positive            2.0  2.143600     NA         5
## 9      threat     Negative            2.0  2.578950     NA         5
## 10     threat     Positive            2.0  1.241300     NA         5
## 11       safe     Negative            1.5  2.118700     NA         5
## 12       safe     Positive            3.5  4.093500     NA         5
## 13     threat     Negative            1.5  0.807115     NA         5
## 14     threat     Positive            4.0  3.464300     NA         5
## 15       safe     Negative            2.0  1.767500     NA         5
## 16       safe     Positive            3.0  1.723800     NA         5
## 17     threat     Negative            3.0  1.445750     NA         5
## 18     threat     Positive            4.0  1.253100     NA         5
## 19       safe     Negative            2.0  1.391000     NA         5
## 20       safe     Positive            3.0  1.267600     NA         5
## 21     threat     Negative            2.0  1.250150     NA         5
## 22     threat     Positive            3.0  1.347050     NA         5
## 23     threat     Negative            3.5  2.681050     NA         5
## 24     threat     Positive            3.5  2.823550     NA         5
## 25       safe     Negative            3.0  2.449450     NA         5
## 26       safe     Positive            3.5  1.776350     NA         5
## 27     threat     Negative            4.0  3.506800     NA         5
## 28     threat     Positive            3.5  1.944250     NA         5
## 29       safe     Negative            3.0  2.145750     NA         5
## 30       safe     Positive            3.0  0.875965     NA         5
## 31     threat     Negative            3.0  2.060950     NA         5
## 32     threat     Positive            4.0  2.341650     NA         5
## 33       safe     Negative            3.0  2.196400     NA         5
## 34       safe     Positive            3.5  1.824440     NA         5
## 35       safe     Negative            1.5  8.743350     NA         3
## 36       safe     Positive            3.5  6.341850     NA         3
## 37     threat     Negative            2.0  5.823150     NA         3
## 38     threat     Positive            2.0  6.674950     NA         3
## 39       safe     Negative            1.5  9.728050     NA         3
## 40       safe     Positive            3.0  3.001800     NA         3
## 41     threat     Negative            1.0  4.531200     NA         3
## 42     threat     Positive            2.5  4.483900     NA         3
## 43       safe     Negative            1.0  4.725650     NA         3
## 44       safe     Positive            2.5  3.326050     NA         3
## 45     threat     Negative            1.0  6.962550     NA         3
## 46     threat     Positive            3.0  2.725000     NA         3
## 47     threat     Negative            2.5  3.453650     NA         5
## 48     threat     Positive            3.0  4.114300     NA         5
## 49       safe     Negative            1.5  5.059200     NA         5
## 50       safe     Positive            3.0  3.957250     NA         5
## 51     threat     Negative            1.5  4.733850     NA         5
## 52     threat     Positive            3.0  1.391300     NA         5
## 53       safe     Negative            3.0  5.071350     NA         5
## 54       safe     Positive            2.5  3.081150     NA         5
## 55     threat     Negative            2.0  3.251150     NA         5
## 56     threat     Positive            2.5  1.546700     NA         5
## 57       safe     Negative            1.5  3.425900     NA         5
## 58       safe     Positive            4.0  3.543900     NA         5
## 59       safe     Negative            3.0  6.441000     NA         5
## 60       safe     Positive            2.5  6.178400     NA         5
## 61     threat     Negative            3.0  3.051600     NA         5
## 62     threat     Positive            2.0  2.469450     NA         5
## 63       safe     Negative            3.5  3.888900     NA         5
## 64       safe     Positive            3.0  3.871800     NA         5
## 65     threat     Negative            1.5  4.928250     NA         5
## 66     threat     Positive            3.0  6.611550     NA         5
## 67       safe     Negative            2.5  3.338250     NA         5
## 68       safe     Positive            3.0  3.218850     NA         5
## 69     threat     Negative            3.0  5.120500     NA         5
## 70     threat     Positive            3.0  3.612900     NA         5
## 71       safe     Negative            3.0  1.046100     NA         6
## 72       safe     Positive            3.5  2.659450     NA         6
## 73     threat     Negative            3.0  2.885350     NA         6
## 74     threat     Positive            3.0  1.562500     NA         6
## 75       safe     Negative            3.0  2.210850     NA         6
## 76       safe     Positive            2.5  1.611050     NA         6
## 77     threat     Negative            3.0  1.616000     NA         6
## 78     threat     Positive            3.5  2.023550     NA         6
## 79       safe     Negative            3.5  2.451100     NA         6
## 80       safe     Positive            3.0  2.224150     NA         6
## 81       safe     Negative            3.0  2.537650     NA         5
## 82       safe     Positive            2.0  4.504750     NA         5
## 83     threat     Negative            2.0  2.506650     NA         5
## 84     threat     Positive            2.0  2.327450     NA         5
## 85       safe     Negative            2.0  2.921550     NA         5
## 86       safe     Positive            3.5  4.302450     NA         5
## 87     threat     Negative            2.0  1.995700     NA         5
## 88     threat     Positive            3.5  2.276200     NA         5
## 89       safe     Negative            2.0  1.949950     NA         5
## 90       safe     Positive            3.0  2.172500     NA         5
## 91     threat     Negative            2.0  2.130400     NA         5
## 92     threat     Positive            3.0  2.791050     NA         5
## 93     threat     Negative            2.5  7.745350     NA         5
## 94     threat     Positive            2.5  5.918600     NA         5
## 95       safe     Negative            2.0  4.411250     NA         5
## 96       safe     Positive            2.0  6.871600     NA         5
## 97     threat     Negative            2.0  8.558650     NA         5
## 98     threat     Positive            2.5  6.090100     NA         5
## 99       safe     Negative            1.0  5.983050     NA         5
## 100      safe     Positive            2.0  8.936500     NA         5
## 101    threat     Negative            2.5  7.954750     NA         5
## 102    threat     Positive            1.5  3.126250     NA         5
## 103      safe     Negative            2.0  2.191700     NA         5
## 104      safe     Positive            1.5  1.876700     NA         5
## 105      safe     Negative            2.5  8.067650     NA         4
## 106      safe     Positive            3.0  7.094100     NA         4
## 107    threat     Negative            2.5 11.697950     NA         4
## 108    threat     Positive            3.0  9.694950     NA         4
## 109      safe     Negative            2.5  7.725550     NA         4
## 110      safe     Positive            2.0  9.076350     NA         4
## 111    threat     Negative            2.5  7.280750     NA         4
## 112    threat     Positive            3.0  3.631600     NA         4
## 113      safe     Negative            3.0  4.997900     NA         4
## 114      safe     Positive            3.0  3.686600     NA         4
## 115    threat     Negative            3.0  2.730250     NA         4
## 116    threat     Positive            3.0  1.966950     NA         4
## 117    threat     Negative            2.5  6.438200     NA         5
## 118    threat     Positive            2.5  3.877850     NA         5
## 119      safe     Negative            1.0  1.623705     NA         5
## 120      safe     Positive            2.5  3.566600     NA         5
## 121    threat     Negative            1.0  2.284100     NA         5
## 122    threat     Positive            2.5  2.016300     NA         5
## 123      safe     Negative            1.0  1.625550     NA         5
## 124      safe     Positive            2.5  1.656700     NA         5
## 125    threat     Negative            1.0  1.230250     NA         5
## 126    threat     Positive            2.5  1.464650     NA         5
## 127      safe     Negative            1.5  2.961700     NA         5
## 128      safe     Positive            2.5  1.315420     NA         5
## 129      safe     Negative            2.5  4.451950     NA         6
## 130      safe     Positive            4.0  4.038450     NA         6
## 131    threat     Negative            2.5  3.709050     NA         6
## 132    threat     Positive            3.5  1.777100     NA         6
## 133      safe     Negative            2.0  2.843000     NA         6
## 134      safe     Positive            3.0  1.965300     NA         6
## 135    threat     Negative            2.0  3.482050     NA         6
## 136    threat     Positive            3.0  1.825750     NA         6
## 137      safe     Negative            2.5  1.761000     NA         6
## 138      safe     Positive            3.0  1.508650     NA         6
## 139    threat     Negative            2.0  2.339600     NA         6
## 140    threat     Positive            3.5  2.823450     NA         6
## 141      safe     Negative            3.0  4.775950     NA         6
## 142      safe     Positive            3.0  4.980850     NA         6
## 143    threat     Negative            3.0  3.546950     NA         6
## 144    threat     Positive            3.0  2.112050     NA         6
## 145      safe     Negative            3.0  3.321300     NA         6
## 146      safe     Positive            3.0  2.288150     NA         6
## 147    threat     Negative            3.5  1.964300     NA         6
## 148    threat     Positive            3.0  1.609450     NA         6
## 149      safe     Negative            4.0  2.749500     NA         6
## 150      safe     Positive            3.0  1.653300     NA         6
## 151    threat     Negative            4.0  2.391680     NA         6
## 152    threat     Positive            3.0  1.759950     NA         6
## 153    threat     Negative            2.0  4.570650     NA         5
## 154    threat     Positive            2.5  3.435850     NA         5
## 155      safe     Negative            2.0  8.972800     NA         5
## 156      safe     Positive            3.5  2.130100     NA         5
## 157    threat     Negative            1.5  4.297000     NA         5
## 158    threat     Positive            3.5  4.868100     NA         5
## 159      safe     Negative            2.5  3.192150     NA         5
## 160      safe     Positive            2.5  2.034500     NA         5
## 161    threat     Negative            1.5  5.353100     NA         5
## 162    threat     Positive            3.0  1.814950     NA         5
## 163      safe     Negative            1.5  1.931270     NA         5
## 164      safe     Positive            3.5  3.524450     NA         5
## 165      safe     Negative            2.5  4.614450     NA         7
## 166      safe     Positive            4.0  4.390550     NA         7
## 167    threat     Negative            3.0  3.242950     NA         7
## 168    threat     Positive            4.0  2.399700     NA         7
## 169      safe     Negative            2.5  2.849900     NA         7
## 170      safe     Positive            4.0  2.420950     NA         7
## 171    threat     Negative            2.0  2.945550     NA         7
## 172    threat     Positive            3.5  3.029200     NA         7
## 173      safe     Negative            2.5  2.742100     NA         7
## 174      safe     Positive            3.0  2.430050     NA         7
## 175    threat     Negative            2.0  2.214750     NA         7
## 176    threat     Positive            3.0  2.059400     NA         7
## 177    threat     Negative            3.5  6.365550     NA         5
## 178    threat     Positive            2.5 13.503700     NA         5
## 179      safe     Negative            1.0  3.155250     NA         5
## 180      safe     Positive            3.0  2.049150     NA         5
## 181    threat     Negative            1.5  2.850200     NA         5
## 182    threat     Positive            3.0  2.181500     NA         5
## 183      safe     Negative            1.0  1.703100     NA         5
## 184      safe     Positive            2.5  3.167800     NA         5
## 185    threat     Negative            1.0  1.420850     NA         5
## 186    threat     Positive            3.0  1.394700     NA         5
## 187      safe     Negative            1.0  1.723700     NA         5
## 188      safe     Positive            3.5  2.381900     NA         5
## 189      safe     Negative            1.0  3.618400     NA         7
## 190      safe     Positive            1.0  4.599800     NA         7
## 191    threat     Negative            1.5  1.565330     NA         7
## 192    threat     Positive            2.0 13.877850     NA         7
## 193      safe     Negative            1.5  2.307250     NA         7
## 194      safe     Positive            3.0  7.615950     NA         7
## 195    threat     Negative            1.0  4.617750     NA         7
## 196    threat     Positive            3.0  4.375300     NA         7
## 197      safe     Negative            1.0  5.358250     NA         7
## 198      safe     Positive            3.5  4.096100     NA         7
## 199    threat     Negative            1.0  6.032200     NA         7
## 200    threat     Positive            3.0  3.535150     NA         7
## 201    threat     Negative            3.5  3.500650     NA         7
## 202    threat     Positive            3.0  2.727900     NA         7
## 203      safe     Negative            3.0  2.529550     NA         7
## 204      safe     Positive            3.0  1.686250     NA         7
## 205    threat     Negative            3.0  1.613400     NA         7
## 206    threat     Positive            3.5  1.340600     NA         7
## 207      safe     Negative            2.5  2.674950     NA         7
## 208      safe     Positive            2.5  5.663700     NA         7
## 209    threat     Negative            2.5  2.337050     NA         7
## 210    threat     Positive            3.0  3.143050     NA         7
## 211      safe     Negative            2.5  2.833400     NA         7
## 212      safe     Positive            2.5  1.445150     NA         7
## 213      safe     Negative            2.0  7.754150     NA         4
## 214      safe     Positive            4.0 10.445500     NA         4
## 215    threat     Negative            2.0  3.940050     NA         4
## 216    threat     Positive            3.0  5.237600     NA         4
## 217      safe     Negative            2.0  2.517400     NA         4
## 218      safe     Positive            3.0  2.740300     NA         4
## 219    threat     Negative            3.0  3.822700     NA         4
## 220    threat     Positive            3.0  2.049850     NA         4
## 221      safe     Negative            2.0  3.088700     NA         4
## 222      safe     Positive            3.0  2.009500     NA         4
## 223    threat     Negative            2.0  1.112775     NA         4
## 224    threat     Positive            3.0  1.281570     NA         4
## 225    threat     Negative            2.0  5.074850     NA         5
## 226    threat     Positive            2.0  4.869750     NA         5
## 227      safe     Negative            1.0  3.751950     NA         5
## 228      safe     Positive            3.0  3.844000     NA         5
## 229    threat     Negative            1.5  3.549400     NA         5
## 230    threat     Positive            3.0  2.440100     NA         5
## 231      safe     Negative            1.0  2.353350     NA         5
## 232      safe     Positive            2.5  2.040700     NA         5
## 233    threat     Negative            1.0  1.471735     NA         5
## 234    threat     Positive            3.0  1.894550     NA         5
## 235      safe     Negative            1.0  1.141320     NA         5
## 236      safe     Positive            3.0  1.144955     NA         5
## 237      safe     Negative            3.5  6.775750     NA         7
## 238      safe     Positive            2.5  3.290700     NA         7
## 239    threat     Negative            2.5  7.501350     NA         7
## 240    threat     Positive            3.0  2.766850     NA         7
## 241      safe     Negative            2.5  2.011250     NA         7
## 242      safe     Positive            3.5  1.631300     NA         7
## 243    threat     Negative            2.0  1.531300     NA         7
## 244    threat     Positive            4.0  1.816275     NA         7
## 245      safe     Negative            2.5  1.292750     NA         7
## 246      safe     Positive            3.5  0.880075     NA         7
## 247    threat     Negative            4.0  4.363300     NA         7
## 248    threat     Positive            3.5  3.630400     NA         7
## 249    threat     Negative            1.5  5.391600     NA         6
## 250    threat     Positive            2.5  4.621200     NA         6
## 251      safe     Negative            1.0  3.308750     NA         6
## 252      safe     Positive            3.0  2.202700     NA         6
## 253    threat     Negative            1.0  1.705000     NA         6
## 254    threat     Positive            3.0  2.211800     NA         6
## 255      safe     Negative            1.0  1.853100     NA         6
## 256      safe     Positive            3.0  2.124000     NA         6
## 257    threat     Negative            2.0  0.989860     NA         6
## 258    threat     Positive            3.5  1.302715     NA         6
## 259      safe     Negative            2.0  2.413400     NA         6
## 260      safe     Positive            3.0  2.049000     NA         6
## 261    threat     Negative            2.5  5.532750     NA         5
## 262    threat     Positive            2.0  3.866150     NA         5
## 263      safe     Negative            3.5  2.040250     NA         5
## 264      safe     Positive            2.5  1.474750     NA         5
## 265    threat     Negative            3.0  2.925900     NA         5
## 266    threat     Positive            2.5  2.592800     NA         5
## 267      safe     Negative            2.5  1.945200     NA         5
## 268      safe     Positive            1.5  1.914350     NA         5
## 269    threat     Negative            3.5  2.487200     NA         5
## 270    threat     Positive            2.5  1.556250     NA         5
## 271      safe     Negative            3.0  3.633900     NA         5
## 272      safe     Positive            3.0  2.901900     NA         5
## 273      safe     Negative            3.0  3.294350     NA         3
## 274      safe     Positive            1.5  6.465950     NA         3
## 275    threat     Negative            2.0  1.847795     NA         3
## 276    threat     Positive            2.0  3.225050     NA         3
## 277      safe     Negative            2.5  1.688465     NA         3
## 278      safe     Positive            1.5  3.435350     NA         3
## 279    threat     Negative            2.5  1.347465     NA         3
## 280    threat     Positive            2.0  2.375750     NA         3
## 281      safe     Negative            3.0  2.757850     NA         3
## 282      safe     Positive            1.5  2.532150     NA         3
## 283    threat     Negative            3.5  4.355450     NA         3
## 284    threat     Positive            2.5  3.057250     NA         3
## 285    threat     Negative            3.5  2.707550     NA         5
## 286    threat     Positive            3.0  6.605600     NA         5
## 287      safe     Negative            1.0  3.006300     NA         5
## 288      safe     Positive            4.0  4.794750     NA         5
## 289    threat     Negative            2.5  2.715800     NA         5
## 290    threat     Positive            2.0  3.849200     NA         5
## 291      safe     Negative            1.5  3.401100     NA         5
## 292      safe     Positive            3.0  3.974100     NA         5
## 293    threat     Negative            3.0  5.123400     NA         5
## 294    threat     Positive            2.0  3.027900     NA         5
## 295      safe     Negative            1.0  2.780665     NA         5
## 296      safe     Positive            3.5  3.843650     NA         5
## 297      safe     Negative            2.5  6.276050     NA         5
## 298      safe     Positive            4.0 12.471850     NA         5
## 299    threat     Negative            1.0  7.571150     NA         5
## 300    threat     Positive            3.0  5.740750     NA         5
## 301      safe     Negative            1.5  6.940200     NA         5
## 302      safe     Positive            3.5  6.047250     NA         5
## 303    threat     Negative            2.0  4.426100     NA         5
## 304    threat     Positive            2.0  3.312100     NA         5
## 305      safe     Negative            1.0  3.691650     NA         5
## 306      safe     Positive            3.0  3.980300     NA         5
## 307    threat     Negative            1.5  4.031235     NA         5
## 308    threat     Positive            3.0  5.515450     NA         5
## 309    threat     Negative            2.5  5.728200     NA         6
## 310    threat     Positive            2.5  3.540250     NA         6
## 311      safe     Negative            1.5  2.580150     NA         6
## 312      safe     Positive            2.0 12.837450     NA         6
## 313    threat     Negative            3.0  4.092800     NA         6
## 314    threat     Positive            2.0  1.982350     NA         6
## 315      safe     Negative            2.0  1.797000     NA         6
## 316      safe     Positive            2.5  1.766300     NA         6
## 317    threat     Negative            4.0  1.923850     NA         6
## 318    threat     Positive            2.5  2.658450     NA         6
## 319      safe     Negative            1.5  3.449850     NA         6
## 320      safe     Positive            2.0  1.912600     NA         6
## 321      safe     Negative            1.5  9.720100     NA         5
## 322      safe     Positive            3.0  7.837950     NA         5
## 323    threat     Negative            1.0  5.158150     NA         5
## 324    threat     Positive            3.0  3.729750     NA         5
## 325      safe     Negative            1.0  2.335800     NA         5
## 326      safe     Positive            3.0  2.865150     NA         5
## 327    threat     Negative            1.0  2.226850     NA         5
## 328    threat     Positive            3.0  2.795600     NA         5
## 329      safe     Negative            1.0  5.546300     NA         5
## 330      safe     Positive            3.0  1.389680     NA         5
## 331    threat     Negative            2.5  5.101800     NA         4
## 332    threat     Positive            3.0  6.448600     NA         4
## 333      safe     Negative            1.5  4.316350     NA         4
## 334      safe     Positive            3.0  3.676350     NA         4
## 335    threat     Negative            1.0  2.326000     NA         4
## 336    threat     Positive            3.0  2.073400     NA         4
## 337      safe     Negative            1.0  1.957850     NA         4
## 338      safe     Positive            3.0  3.407250     NA         4
## 339    threat     Negative            1.0  1.775900     NA         4
## 340    threat     Positive            3.0  1.437300     NA         4
## 341      safe     Negative            1.5  1.497250     NA         4
## 342      safe     Positive            3.0  1.425250     NA         4
## 343      safe     Negative            3.0  5.403750     NA         5
## 344      safe     Positive            2.5  5.004150     NA         5
## 345    threat     Negative            2.5  3.820300     NA         5
## 346    threat     Positive            2.5  3.120200     NA         5
## 347      safe     Negative            2.5  3.058800     NA         5
## 348      safe     Positive            2.5  2.986500     NA         5
## 349    threat     Negative            1.5  3.118300     NA         5
## 350    threat     Positive            1.0  1.865600     NA         5
## 351      safe     Negative            1.0  4.196900     NA         5
## 352      safe     Positive            2.5  2.739550     NA         5
## 353    threat     Negative            1.0  1.019960     NA         5
## 354    threat     Positive            1.5  3.337300     NA         5
## 355    threat     Negative            1.0  3.387500     NA         5
## 356    threat     Positive            3.0  3.797850     NA         5
## 357      safe     Negative            1.0  3.813500     NA         5
## 358      safe     Positive            3.0  3.844150     NA         5
## 359    threat     Negative            1.0  2.801600     NA         5
## 360    threat     Positive            3.0  4.065750     NA         5
## 361      safe     Negative            1.0  1.997200     NA         5
## 362      safe     Positive            3.0  1.897050     NA         5
## 363    threat     Negative            1.0  1.809550     NA         5
## 364    threat     Positive            3.0  3.235950     NA         5
## 365      safe     Negative            1.0  1.135350     NA         5
## 366      safe     Positive            3.0  2.069550     NA         5
## 367      safe     Negative            2.5  6.080500     NA         4
## 368      safe     Positive            2.5  6.194700     NA         4
## 369    threat     Negative            2.0  1.465265     NA         4
## 370    threat     Positive            2.0  5.588000     NA         4
## 371      safe     Negative            1.5  1.905795     NA         4
## 372      safe     Positive            2.0  5.451300     NA         4
## 373    threat     Negative            2.0  1.717335     NA         4
## 374    threat     Positive            1.5  4.980650     NA         4
## 375      safe     Negative            1.5  2.166015     NA         4
## 376      safe     Positive            2.5  6.800450     NA         4
## 377    threat     Negative            2.0  4.431900     NA         4
## 378    threat     Positive            2.5  3.026750     NA         4
## 379    threat     Negative            2.5  4.372300     NA         4
## 380    threat     Positive            3.0  2.586350     NA         4
## 381      safe     Negative            1.0  2.174600     NA         4
## 382      safe     Positive            1.5  1.914500     NA         4
## 383    threat     Negative            1.5  4.051350     NA         4
## 384    threat     Positive            2.0  1.934750     NA         4
## 385      safe     Negative            1.0  2.010800     NA         4
## 386      safe     Positive            1.5  1.531150     NA         4
## 387    threat     Negative            3.0  2.622700     NA         4
## 388    threat     Positive            2.0  2.156650     NA         4
## 389      safe     Negative            1.0  3.167550     NA         4
## 390      safe     Positive            3.0  4.438400     NA         4
## 391      safe     Negative            2.5  3.137000     NA         5
## 392      safe     Positive            4.0  5.092300     NA         5
## 393    threat     Negative            2.5  1.479695     NA         5
## 394    threat     Positive            4.0  6.619200     NA         5
## 395      safe     Negative            2.5  3.480250     NA         5
## 396      safe     Positive            3.5  9.378650     NA         5
## 397    threat     Negative            3.0  1.661770     NA         5
## 398    threat     Positive            3.5  6.118400     NA         5
## 399      safe     Negative            3.5  2.621800     NA         5
## 400      safe     Positive            3.0  7.354300     NA         5
## 401    threat     Negative            3.5  3.504100     NA         5
## 402    threat     Positive            3.5  5.360300     NA         5
## 403    threat     Negative            1.5  5.926300     NA         7
## 404    threat     Positive            1.5  1.510800     NA         7
## 405      safe     Negative            2.5  3.857150     NA         7
## 406      safe     Positive            3.0  1.545050     NA         7
## 407    threat     Negative            3.5  2.923650     NA         7
## 408    threat     Positive            2.5  2.839850     NA         7
## 409      safe     Negative            2.0  2.401150     NA         7
## 410      safe     Positive            2.0  2.146600     NA         7
## 411    threat     Negative            3.5  2.476800     NA         7
## 412    threat     Positive            1.5  1.457300     NA         7
## 413      safe     Negative            2.0  0.401840     NA         7
## 414      safe     Positive            2.0  0.251545     NA         7
## 415      safe     Negative            2.0  2.707450     NA         6
## 416      safe     Positive            2.5  3.262900     NA         6
## 417    threat     Negative            3.0  3.044850     NA         6
## 418    threat     Positive            1.0  2.536400     NA         6
## 419      safe     Negative            2.0  3.946550     NA         6
## 420      safe     Positive            2.5  2.067650     NA         6
## 421    threat     Negative            2.5  2.584950     NA         6
## 422    threat     Positive            1.5  1.938500     NA         6
## 423      safe     Negative            1.5  1.879500     NA         6
## 424      safe     Positive            2.5  1.899550     NA         6
## 425    threat     Negative            2.0  1.894050     NA         6
## 426    threat     Positive            2.0  1.726975     NA         6
## 427    threat     Negative            4.0  6.772800     NA         6
## 428    threat     Positive            3.0  2.830300     NA         6
## 429      safe     Negative            3.5  3.308300     NA         6
## 430      safe     Positive            2.5  3.009900     NA         6
## 431    threat     Negative            3.0  2.509350     NA         6
## 432    threat     Positive            3.5  2.148300     NA         6
## 433      safe     Negative            3.0  3.695100     NA         6
## 434      safe     Positive            1.5  2.710700     NA         6
## 435    threat     Negative            2.0  2.808900     NA         6
## 436    threat     Positive            2.0  1.994950     NA         6
## 437      safe     Negative            2.0  1.747900     NA         6
## 438      safe     Positive            3.5  1.681050     NA         6
## 439      safe     Negative            2.0  3.173450     NA         5
## 440      safe     Positive            2.5  3.591850     NA         5
## 441    threat     Negative            3.0  4.096300     NA         5
## 442    threat     Positive            1.5  3.704050     NA         5
## 443      safe     Negative            1.5  4.757450     NA         5
## 444      safe     Positive            3.0  3.709700     NA         5
## 445    threat     Negative            3.0  2.836350     NA         5
## 446    threat     Positive            1.5  2.128850     NA         5
## 447      safe     Negative            2.0  5.122050     NA         5
## 448      safe     Positive            3.5  2.433700     NA         5
## 449    threat     Negative            3.0  1.849350     NA         5
## 450    threat     Positive            1.5  1.860250     NA         5
## 451    threat     Negative            2.5  4.443700     NA         5
## 452    threat     Positive            3.5  5.909950     NA         5
## 453      safe     Negative            1.0  4.852800     NA         5
## 454      safe     Positive            3.0  6.099500     NA         5
## 455    threat     Negative            1.0  2.979550     NA         5
## 456    threat     Positive            3.5  4.594100     NA         5
## 457      safe     Negative            1.0  2.565450     NA         5
## 458      safe     Positive            3.0  3.130750     NA         5
## 459    threat     Negative            3.0  5.915600     NA         5
## 460    threat     Positive            2.5  3.092050     NA         5
## 461      safe     Negative            3.5  4.059300     NA         5
## 462      safe     Positive            2.5  1.950200     NA         5
## 463      safe     Negative            2.5  4.538450     NA         6
## 464      safe     Positive            2.0  3.680850     NA         6
## 465    threat     Negative            4.0  2.056715     NA         6
## 466    threat     Positive            2.5  1.418650     NA         6
## 467      safe     Negative            2.0  1.469115     NA         6
## 468      safe     Positive            2.0  1.314505     NA         6
## 469    threat     Negative            3.5  1.331700     NA         6
## 470    threat     Positive            2.5  4.057300     NA         6
## 471      safe     Negative            2.0  1.417750     NA         6
## 472      safe     Positive            2.0  1.130385     NA         6
## 473    threat     Negative            4.0  1.586105     NA         6
## 474    threat     Positive            1.0  1.005095     NA         6
## 475    threat     Negative            4.0 11.189150     NA         6
## 476    threat     Positive            1.0  6.151150     NA         6
## 477      safe     Negative            4.0  3.024000     NA         6
## 478      safe     Positive            2.0  2.991100     NA         6
## 479    threat     Negative            4.0  4.473050     NA         6
## 480    threat     Positive            2.5  3.710250     NA         6
## 481      safe     Negative            3.5  3.769450     NA         6
## 482      safe     Positive            1.5  2.396750     NA         6
## 483    threat     Negative            4.0  2.195100     NA         6
## 484    threat     Positive            2.5  1.802050     NA         6
## 485      safe     Negative            4.0  1.995300     NA         6
## 486      safe     Positive            2.5  1.067620     NA         6
## 487      safe     Negative            3.5  7.324800     NA         6
## 488      safe     Positive            3.0  4.528900     NA         6
## 489    threat     Negative            3.5  2.565300     NA         6
## 490    threat     Positive            3.0  7.454200     NA         6
## 491      safe     Negative            3.0  2.765950     NA         6
## 492      safe     Positive            3.5  1.512500     NA         6
## 493    threat     Negative            4.0  1.782800     NA         6
## 494    threat     Positive            3.0  2.827750     NA         6
## 495      safe     Negative            3.0  2.024150     NA         6
## 496      safe     Positive            3.5  2.553200     NA         6
## 497    threat     Negative            4.0  1.842550     NA         6
## 498    threat     Positive            3.0  2.002750     NA         6
## 499    threat     Negative            3.0  5.640050     NA         4
## 500    threat     Positive            2.0  6.743300     NA         4
## 501      safe     Negative            1.0  1.706855     NA         4
## 502      safe     Positive            3.0  5.275250     NA         4
## 503    threat     Negative            2.5  4.313250     NA         4
## 504    threat     Positive            2.5  4.630450     NA         4
## 505      safe     Negative            1.0  3.020900     NA         4
## 506      safe     Positive            3.0  3.943800     NA         4
## 507    threat     Negative            1.5  3.284250     NA         4
## 508    threat     Positive            3.0  3.551700     NA         4
## 509      safe     Negative            1.0  2.993650     NA         4
## 510      safe     Positive            2.5  2.521400     NA         4
## 511      safe     Negative            2.5  5.912600     NA         4
## 512      safe     Positive            3.5  4.860800     NA         4
## 513    threat     Negative            2.0  2.192030     NA         4
## 514    threat     Positive            3.0  4.345950     NA         4
## 515      safe     Negative            3.0  5.923950     NA         4
## 516      safe     Positive            3.0  2.529100     NA         4
## 517    threat     Negative            4.0  4.487650     NA         4
## 518    threat     Positive            3.0  2.560900     NA         4
## 519      safe     Negative            3.0  2.826050     NA         4
## 520      safe     Positive            3.0  2.150000     NA         4
## 521    threat     Negative            4.0  2.573450     NA         4
## 522    threat     Positive            3.0  2.357750     NA         4
## 523    threat     Negative            3.5  7.842950     NA         4
## 524    threat     Positive            3.0  7.939200     NA         4
## 525      safe     Negative            1.0  4.149400     NA         4
## 526      safe     Positive            3.0  5.069250     NA         4
## 527    threat     Negative            2.0  4.477400     NA         4
## 528    threat     Positive            2.0  4.868150     NA         4
## 529      safe     Negative            1.0  4.347700     NA         4
## 530      safe     Positive            2.0  5.212800     NA         4
## 531    threat     Negative            2.0  3.220200     NA         4
## 532    threat     Positive            2.0  4.365500     NA         4
## 533      safe     Negative            1.0  3.090650     NA         4
## 534      safe     Positive            4.0  4.334200     NA         4
## 535      safe     Negative            2.0  6.751100     NA         4
## 536      safe     Positive            3.0  3.623000     NA         4
## 537    threat     Negative            3.0  3.844050     NA         4
## 538    threat     Positive            2.0  3.426050     NA         4
## 539      safe     Negative            2.5  2.565150     NA         4
## 540      safe     Positive            2.0  3.694400     NA         4
## 541    threat     Negative            4.0  2.217350     NA         4
## 542    threat     Positive            1.5  3.204250     NA         4
## 543      safe     Negative            1.5  2.830550     NA         4
## 544      safe     Positive            2.5  2.670700     NA         4
## 545    threat     Negative            4.0  3.205400     NA         4
## 546    threat     Positive            1.5  1.845200     NA         4
## 547    threat     Negative            1.5  6.009350     NA         6
## 548    threat     Positive            2.5  4.984150     NA         6
## 549      safe     Negative            2.0  3.401700     NA         6
## 550      safe     Positive            3.0  4.077650     NA         6
## 551    threat     Negative            3.0  2.108650     NA         6
## 552    threat     Positive            2.5  5.229350     NA         6
## 553      safe     Negative            1.0  3.622550     NA         6
## 554      safe     Positive            3.0  1.883450     NA         6
## 555    threat     Negative            1.0  4.023900     NA         6
## 556    threat     Positive            3.5  2.075400     NA         6
## 557      safe     Negative            1.0  3.018900     NA         6
## 558      safe     Positive            3.0  1.578350     NA         6
##     important_math anxious happy safe stressed life_stress   sleep
## 1                6       3     2    3        3           4  4.5000
## 2                6       3     2    3        3           4  4.5000
## 3                6       3     2    3        3           4  4.5000
## 4                6       3     2    3        3           4  4.5000
## 5                6       3     2    3        3           4  4.5000
## 6                6       3     2    3        3           4  4.5000
## 7                6       3     2    3        3           4  4.5000
## 8                6       3     2    3        3           4  4.5000
## 9                6       3     2    3        3           4  4.5000
## 10               6       3     2    3        3           4  4.5000
## 11               6       2     5    6        2           2  8.5000
## 12               6       2     5    6        2           2  8.5000
## 13               6       2     5    6        2           2  8.5000
## 14               6       2     5    6        2           2  8.5000
## 15               6       2     5    6        2           2  8.5000
## 16               6       2     5    6        2           2  8.5000
## 17               6       2     5    6        2           2  8.5000
## 18               6       2     5    6        2           2  8.5000
## 19               6       2     5    6        2           2  8.5000
## 20               6       2     5    6        2           2  8.5000
## 21               6       2     5    6        2           2  8.5000
## 22               6       2     5    6        2           2  8.5000
## 23               7       4     2    5        5           4  9.0000
## 24               7       4     2    5        5           4  9.0000
## 25               7       4     2    5        5           4  9.0000
## 26               7       4     2    5        5           4  9.0000
## 27               7       4     2    5        5           4  9.0000
## 28               7       4     2    5        5           4  9.0000
## 29               7       4     2    5        5           4  9.0000
## 30               7       4     2    5        5           4  9.0000
## 31               7       4     2    5        5           4  9.0000
## 32               7       4     2    5        5           4  9.0000
## 33               7       4     2    5        5           4  9.0000
## 34               7       4     2    5        5           4  9.0000
## 35               2       2     3    5        2           2  6.5000
## 36               2       2     3    5        2           2  6.5000
## 37               2       2     3    5        2           2  6.5000
## 38               2       2     3    5        2           2  6.5000
## 39               2       2     3    5        2           2  6.5000
## 40               2       2     3    5        2           2  6.5000
## 41               2       2     3    5        2           2  6.5000
## 42               2       2     3    5        2           2  6.5000
## 43               2       2     3    5        2           2  6.5000
## 44               2       2     3    5        2           2  6.5000
## 45               2       2     3    5        2           2  6.5000
## 46               2       2     3    5        2           2  6.5000
## 47               5       3     5    6        3           4  8.0000
## 48               5       3     5    6        3           4  8.0000
## 49               5       3     5    6        3           4  8.0000
## 50               5       3     5    6        3           4  8.0000
## 51               5       3     5    6        3           4  8.0000
## 52               5       3     5    6        3           4  8.0000
## 53               5       3     5    6        3           4  8.0000
## 54               5       3     5    6        3           4  8.0000
## 55               5       3     5    6        3           4  8.0000
## 56               5       3     5    6        3           4  8.0000
## 57               5       3     5    6        3           4  8.0000
## 58               5       3     5    6        3           4  8.0000
## 59               5       6     2    5        6           3  8.0000
## 60               5       6     2    5        6           3  8.0000
## 61               5       6     2    5        6           3  8.0000
## 62               5       6     2    5        6           3  8.0000
## 63               5       6     2    5        6           3  8.0000
## 64               5       6     2    5        6           3  8.0000
## 65               5       6     2    5        6           3  8.0000
## 66               5       6     2    5        6           3  8.0000
## 67               5       6     2    5        6           3  8.0000
## 68               5       6     2    5        6           3  8.0000
## 69               5       6     2    5        6           3  8.0000
## 70               5       6     2    5        6           3  8.0000
## 71               6       3     2    3        3           2  8.0000
## 72               6       3     2    3        3           2  8.0000
## 73               6       3     2    3        3           2  8.0000
## 74               6       3     2    3        3           2  8.0000
## 75               6       3     2    3        3           2  8.0000
## 76               6       3     2    3        3           2  8.0000
## 77               6       3     2    3        3           2  8.0000
## 78               6       3     2    3        3           2  8.0000
## 79               6       3     2    3        3           2  8.0000
## 80               6       3     2    3        3           2  8.0000
## 81               5       5     3    3        5           4  6.0000
## 82               5       5     3    3        5           4  6.0000
## 83               5       5     3    3        5           4  6.0000
## 84               5       5     3    3        5           4  6.0000
## 85               5       5     3    3        5           4  6.0000
## 86               5       5     3    3        5           4  6.0000
## 87               5       5     3    3        5           4  6.0000
## 88               5       5     3    3        5           4  6.0000
## 89               5       5     3    3        5           4  6.0000
## 90               5       5     3    3        5           4  6.0000
## 91               5       5     3    3        5           4  6.0000
## 92               5       5     3    3        5           4  6.0000
## 93               7       3     2    3        3           3  7.0000
## 94               7       3     2    3        3           3  7.0000
## 95               7       3     2    3        3           3  7.0000
## 96               7       3     2    3        3           3  7.0000
## 97               7       3     2    3        3           3  7.0000
## 98               7       3     2    3        3           3  7.0000
## 99               7       3     2    3        3           3  7.0000
## 100              7       3     2    3        3           3  7.0000
## 101              7       3     2    3        3           3  7.0000
## 102              7       3     2    3        3           3  7.0000
## 103              7       3     2    3        3           3  7.0000
## 104              7       3     2    3        3           3  7.0000
## 105              4       5     2    7        5           4 10.0000
## 106              4       5     2    7        5           4 10.0000
## 107              4       5     2    7        5           4 10.0000
## 108              4       5     2    7        5           4 10.0000
## 109              4       5     2    7        5           4 10.0000
## 110              4       5     2    7        5           4 10.0000
## 111              4       5     2    7        5           4 10.0000
## 112              4       5     2    7        5           4 10.0000
## 113              4       5     2    7        5           4 10.0000
## 114              4       5     2    7        5           4 10.0000
## 115              4       5     2    7        5           4 10.0000
## 116              4       5     2    7        5           4 10.0000
## 117              5       1     1    7        2           1  8.5000
## 118              5       1     1    7        2           1  8.5000
## 119              5       1     1    7        2           1  8.5000
## 120              5       1     1    7        2           1  8.5000
## 121              5       1     1    7        2           1  8.5000
## 122              5       1     1    7        2           1  8.5000
## 123              5       1     1    7        2           1  8.5000
## 124              5       1     1    7        2           1  8.5000
## 125              5       1     1    7        2           1  8.5000
## 126              5       1     1    7        2           1  8.5000
## 127              5       1     1    7        2           1  8.5000
## 128              5       1     1    7        2           1  8.5000
## 129              7       3     3    6        4           3  8.5000
## 130              7       3     3    6        4           3  8.5000
## 131              7       3     3    6        4           3  8.5000
## 132              7       3     3    6        4           3  8.5000
## 133              7       3     3    6        4           3  8.5000
## 134              7       3     3    6        4           3  8.5000
## 135              7       3     3    6        4           3  8.5000
## 136              7       3     3    6        4           3  8.5000
## 137              7       3     3    6        4           3  8.5000
## 138              7       3     3    6        4           3  8.5000
## 139              7       3     3    6        4           3  8.5000
## 140              7       3     3    6        4           3  8.5000
## 141              6       3     1    6        6           4  8.0000
## 142              6       3     1    6        6           4  8.0000
## 143              6       3     1    6        6           4  8.0000
## 144              6       3     1    6        6           4  8.0000
## 145              6       3     1    6        6           4  8.0000
## 146              6       3     1    6        6           4  8.0000
## 147              6       3     1    6        6           4  8.0000
## 148              6       3     1    6        6           4  8.0000
## 149              6       3     1    6        6           4  8.0000
## 150              6       3     1    6        6           4  8.0000
## 151              6       3     1    6        6           4  8.0000
## 152              6       3     1    6        6           4  8.0000
## 153              4       3     3    4        3           3  8.0000
## 154              4       3     3    4        3           3  8.0000
## 155              4       3     3    4        3           3  8.0000
## 156              4       3     3    4        3           3  8.0000
## 157              4       3     3    4        3           3  8.0000
## 158              4       3     3    4        3           3  8.0000
## 159              4       3     3    4        3           3  8.0000
## 160              4       3     3    4        3           3  8.0000
## 161              4       3     3    4        3           3  8.0000
## 162              4       3     3    4        3           3  8.0000
## 163              4       3     3    4        3           3  8.0000
## 164              4       3     3    4        3           3  8.0000
## 165              7       2     5    7        2           6  7.0000
## 166              7       2     5    7        2           6  7.0000
## 167              7       2     5    7        2           6  7.0000
## 168              7       2     5    7        2           6  7.0000
## 169              7       2     5    7        2           6  7.0000
## 170              7       2     5    7        2           6  7.0000
## 171              7       2     5    7        2           6  7.0000
## 172              7       2     5    7        2           6  7.0000
## 173              7       2     5    7        2           6  7.0000
## 174              7       2     5    7        2           6  7.0000
## 175              7       2     5    7        2           6  7.0000
## 176              7       2     5    7        2           6  7.0000
## 177              5       2     5    7        3           5  8.5000
## 178              5       2     5    7        3           5  8.5000
## 179              5       2     5    7        3           5  8.5000
## 180              5       2     5    7        3           5  8.5000
## 181              5       2     5    7        3           5  8.5000
## 182              5       2     5    7        3           5  8.5000
## 183              5       2     5    7        3           5  8.5000
## 184              5       2     5    7        3           5  8.5000
## 185              5       2     5    7        3           5  8.5000
## 186              5       2     5    7        3           5  8.5000
## 187              5       2     5    7        3           5  8.5000
## 188              5       2     5    7        3           5  8.5000
## 189              5       1     5    7        1           4  6.5000
## 190              5       1     5    7        1           4  6.5000
## 191              5       1     5    7        1           4  6.5000
## 192              5       1     5    7        1           4  6.5000
## 193              5       1     5    7        1           4  6.5000
## 194              5       1     5    7        1           4  6.5000
## 195              5       1     5    7        1           4  6.5000
## 196              5       1     5    7        1           4  6.5000
## 197              5       1     5    7        1           4  6.5000
## 198              5       1     5    7        1           4  6.5000
## 199              5       1     5    7        1           4  6.5000
## 200              5       1     5    7        1           4  6.5000
## 201              7       2     3    5        2           2  5.0000
## 202              7       2     3    5        2           2  5.0000
## 203              7       2     3    5        2           2  5.0000
## 204              7       2     3    5        2           2  5.0000
## 205              7       2     3    5        2           2  5.0000
## 206              7       2     3    5        2           2  5.0000
## 207              7       2     3    5        2           2  5.0000
## 208              7       2     3    5        2           2  5.0000
## 209              7       2     3    5        2           2  5.0000
## 210              7       2     3    5        2           2  5.0000
## 211              7       2     3    5        2           2  5.0000
## 212              7       2     3    5        2           2  5.0000
## 213              0       3     3    7        4           2  8.5000
## 214              0       3     3    7        4           2  8.5000
## 215              0       3     3    7        4           2  8.5000
## 216              0       3     3    7        4           2  8.5000
## 217              0       3     3    7        4           2  8.5000
## 218              0       3     3    7        4           2  8.5000
## 219              0       3     3    7        4           2  8.5000
## 220              0       3     3    7        4           2  8.5000
## 221              0       3     3    7        4           2  8.5000
## 222              0       3     3    7        4           2  8.5000
## 223              0       3     3    7        4           2  8.5000
## 224              0       3     3    7        4           2  8.5000
## 225              4       3     5    4        2           3  7.0000
## 226              4       3     5    4        2           3  7.0000
## 227              4       3     5    4        2           3  7.0000
## 228              4       3     5    4        2           3  7.0000
## 229              4       3     5    4        2           3  7.0000
## 230              4       3     5    4        2           3  7.0000
## 231              4       3     5    4        2           3  7.0000
## 232              4       3     5    4        2           3  7.0000
## 233              4       3     5    4        2           3  7.0000
## 234              4       3     5    4        2           3  7.0000
## 235              4       3     5    4        2           3  7.0000
## 236              4       3     5    4        2           3  7.0000
## 237              7       3     4    4        3           3  9.0000
## 238              7       3     4    4        3           3  9.0000
## 239              7       3     4    4        3           3  9.0000
## 240              7       3     4    4        3           3  9.0000
## 241              7       3     4    4        3           3  9.0000
## 242              7       3     4    4        3           3  9.0000
## 243              7       3     4    4        3           3  9.0000
## 244              7       3     4    4        3           3  9.0000
## 245              7       3     4    4        3           3  9.0000
## 246              7       3     4    4        3           3  9.0000
## 247              7       3     4    4        3           3  9.0000
## 248              7       3     4    4        3           3  9.0000
## 249              7       2     3    6        2           3  6.0000
## 250              7       2     3    6        2           3  6.0000
## 251              7       2     3    6        2           3  6.0000
## 252              7       2     3    6        2           3  6.0000
## 253              7       2     3    6        2           3  6.0000
## 254              7       2     3    6        2           3  6.0000
## 255              7       2     3    6        2           3  6.0000
## 256              7       2     3    6        2           3  6.0000
## 257              7       2     3    6        2           3  6.0000
## 258              7       2     3    6        2           3  6.0000
## 259              7       2     3    6        2           3  6.0000
## 260              7       2     3    6        2           3  6.0000
## 261              6       4     2    4        5           3  7.5000
## 262              6       4     2    4        5           3  7.5000
## 263              6       4     2    4        5           3  7.5000
## 264              6       4     2    4        5           3  7.5000
## 265              6       4     2    4        5           3  7.5000
## 266              6       4     2    4        5           3  7.5000
## 267              6       4     2    4        5           3  7.5000
## 268              6       4     2    4        5           3  7.5000
## 269              6       4     2    4        5           3  7.5000
## 270              6       4     2    4        5           3  7.5000
## 271              6       4     2    4        5           3  7.5000
## 272              6       4     2    4        5           3  7.5000
## 273              4       6     1    3        5           4  9.0000
## 274              4       6     1    3        5           4  9.0000
## 275              4       6     1    3        5           4  9.0000
## 276              4       6     1    3        5           4  9.0000
## 277              4       6     1    3        5           4  9.0000
## 278              4       6     1    3        5           4  9.0000
## 279              4       6     1    3        5           4  9.0000
## 280              4       6     1    3        5           4  9.0000
## 281              4       6     1    3        5           4  9.0000
## 282              4       6     1    3        5           4  9.0000
## 283              4       6     1    3        5           4  9.0000
## 284              4       6     1    3        5           4  9.0000
## 285              4       3     4    5        6           3  9.0000
## 286              4       3     4    5        6           3  9.0000
## 287              4       3     4    5        6           3  9.0000
## 288              4       3     4    5        6           3  9.0000
## 289              4       3     4    5        6           3  9.0000
## 290              4       3     4    5        6           3  9.0000
## 291              4       3     4    5        6           3  9.0000
## 292              4       3     4    5        6           3  9.0000
## 293              4       3     4    5        6           3  9.0000
## 294              4       3     4    5        6           3  9.0000
## 295              4       3     4    5        6           3  9.0000
## 296              4       3     4    5        6           3  9.0000
## 297              7       2     5    5        2           4  7.0000
## 298              7       2     5    5        2           4  7.0000
## 299              7       2     5    5        2           4  7.0000
## 300              7       2     5    5        2           4  7.0000
## 301              7       2     5    5        2           4  7.0000
## 302              7       2     5    5        2           4  7.0000
## 303              7       2     5    5        2           4  7.0000
## 304              7       2     5    5        2           4  7.0000
## 305              7       2     5    5        2           4  7.0000
## 306              7       2     5    5        2           4  7.0000
## 307              7       2     5    5        2           4  7.0000
## 308              7       2     5    5        2           4  7.0000
## 309              5       5     4    4        5           4  8.0000
## 310              5       5     4    4        5           4  8.0000
## 311              5       5     4    4        5           4  8.0000
## 312              5       5     4    4        5           4  8.0000
## 313              5       5     4    4        5           4  8.0000
## 314              5       5     4    4        5           4  8.0000
## 315              5       5     4    4        5           4  8.0000
## 316              5       5     4    4        5           4  8.0000
## 317              5       5     4    4        5           4  8.0000
## 318              5       5     4    4        5           4  8.0000
## 319              5       5     4    4        5           4  8.0000
## 320              5       5     4    4        5           4  8.0000
## 321              6       3     5    6        2           2  8.0000
## 322              6       3     5    6        2           2  8.0000
## 323              6       3     5    6        2           2  8.0000
## 324              6       3     5    6        2           2  8.0000
## 325              6       3     5    6        2           2  8.0000
## 326              6       3     5    6        2           2  8.0000
## 327              6       3     5    6        2           2  8.0000
## 328              6       3     5    6        2           2  8.0000
## 329              6       3     5    6        2           2  8.0000
## 330              6       3     5    6        2           2  8.0000
## 331              2       3     2    7        3           2  9.0000
## 332              2       3     2    7        3           2  9.0000
## 333              2       3     2    7        3           2  9.0000
## 334              2       3     2    7        3           2  9.0000
## 335              2       3     2    7        3           2  9.0000
## 336              2       3     2    7        3           2  9.0000
## 337              2       3     2    7        3           2  9.0000
## 338              2       3     2    7        3           2  9.0000
## 339              2       3     2    7        3           2  9.0000
## 340              2       3     2    7        3           2  9.0000
## 341              2       3     2    7        3           2  9.0000
## 342              2       3     2    7        3           2  9.0000
## 343              5       3     2    5        3           3  8.0000
## 344              5       3     2    5        3           3  8.0000
## 345              5       3     2    5        3           3  8.0000
## 346              5       3     2    5        3           3  8.0000
## 347              5       3     2    5        3           3  8.0000
## 348              5       3     2    5        3           3  8.0000
## 349              5       3     2    5        3           3  8.0000
## 350              5       3     2    5        3           3  8.0000
## 351              5       3     2    5        3           3  8.0000
## 352              5       3     2    5        3           3  8.0000
## 353              5       3     2    5        3           3  8.0000
## 354              5       3     2    5        3           3  8.0000
## 355              7       1     3    7        1           3  8.8333
## 356              7       1     3    7        1           3  8.8333
## 357              7       1     3    7        1           3  8.8333
## 358              7       1     3    7        1           3  8.8333
## 359              7       1     3    7        1           3  8.8333
## 360              7       1     3    7        1           3  8.8333
## 361              7       1     3    7        1           3  8.8333
## 362              7       1     3    7        1           3  8.8333
## 363              7       1     3    7        1           3  8.8333
## 364              7       1     3    7        1           3  8.8333
## 365              7       1     3    7        1           3  8.8333
## 366              7       1     3    7        1           3  8.8333
## 367              5       5     3    5        4           6 12.0000
## 368              5       5     3    5        4           6 12.0000
## 369              5       5     3    5        4           6 12.0000
## 370              5       5     3    5        4           6 12.0000
## 371              5       5     3    5        4           6 12.0000
## 372              5       5     3    5        4           6 12.0000
## 373              5       5     3    5        4           6 12.0000
## 374              5       5     3    5        4           6 12.0000
## 375              5       5     3    5        4           6 12.0000
## 376              5       5     3    5        4           6 12.0000
## 377              5       5     3    5        4           6 12.0000
## 378              5       5     3    5        4           6 12.0000
## 379              6       4     3    6        5           3  4.5000
## 380              6       4     3    6        5           3  4.5000
## 381              6       4     3    6        5           3  4.5000
## 382              6       4     3    6        5           3  4.5000
## 383              6       4     3    6        5           3  4.5000
## 384              6       4     3    6        5           3  4.5000
## 385              6       4     3    6        5           3  4.5000
## 386              6       4     3    6        5           3  4.5000
## 387              6       4     3    6        5           3  4.5000
## 388              6       4     3    6        5           3  4.5000
## 389              6       4     3    6        5           3  4.5000
## 390              6       4     3    6        5           3  4.5000
## 391              4       3     3    7        6           5  6.0000
## 392              4       3     3    7        6           5  6.0000
## 393              4       3     3    7        6           5  6.0000
## 394              4       3     3    7        6           5  6.0000
## 395              4       3     3    7        6           5  6.0000
## 396              4       3     3    7        6           5  6.0000
## 397              4       3     3    7        6           5  6.0000
## 398              4       3     3    7        6           5  6.0000
## 399              4       3     3    7        6           5  6.0000
## 400              4       3     3    7        6           5  6.0000
## 401              4       3     3    7        6           5  6.0000
## 402              4       3     3    7        6           5  6.0000
## 403              5       3     2    4        5           3  7.0000
## 404              5       3     2    4        5           3  7.0000
## 405              5       3     2    4        5           3  7.0000
## 406              5       3     2    4        5           3  7.0000
## 407              5       3     2    4        5           3  7.0000
## 408              5       3     2    4        5           3  7.0000
## 409              5       3     2    4        5           3  7.0000
## 410              5       3     2    4        5           3  7.0000
## 411              5       3     2    4        5           3  7.0000
## 412              5       3     2    4        5           3  7.0000
## 413              5       3     2    4        5           3  7.0000
## 414              5       3     2    4        5           3  7.0000
## 415              6       3     2    4        3           4  8.0000
## 416              6       3     2    4        3           4  8.0000
## 417              6       3     2    4        3           4  8.0000
## 418              6       3     2    4        3           4  8.0000
## 419              6       3     2    4        3           4  8.0000
## 420              6       3     2    4        3           4  8.0000
## 421              6       3     2    4        3           4  8.0000
## 422              6       3     2    4        3           4  8.0000
## 423              6       3     2    4        3           4  8.0000
## 424              6       3     2    4        3           4  8.0000
## 425              6       3     2    4        3           4  8.0000
## 426              6       3     2    4        3           4  8.0000
## 427              7       6     2    3        6           5  9.0000
## 428              7       6     2    3        6           5  9.0000
## 429              7       6     2    3        6           5  9.0000
## 430              7       6     2    3        6           5  9.0000
## 431              7       6     2    3        6           5  9.0000
## 432              7       6     2    3        6           5  9.0000
## 433              7       6     2    3        6           5  9.0000
## 434              7       6     2    3        6           5  9.0000
## 435              7       6     2    3        6           5  9.0000
## 436              7       6     2    3        6           5  9.0000
## 437              7       6     2    3        6           5  9.0000
## 438              7       6     2    3        6           5  9.0000
## 439              6       5     2    5        5           2  7.5000
## 440              6       5     2    5        5           2  7.5000
## 441              6       5     2    5        5           2  7.5000
## 442              6       5     2    5        5           2  7.5000
## 443              6       5     2    5        5           2  7.5000
## 444              6       5     2    5        5           2  7.5000
## 445              6       5     2    5        5           2  7.5000
## 446              6       5     2    5        5           2  7.5000
## 447              6       5     2    5        5           2  7.5000
## 448              6       5     2    5        5           2  7.5000
## 449              6       5     2    5        5           2  7.5000
## 450              6       5     2    5        5           2  7.5000
## 451              7       5     2    5        4           4  6.0000
## 452              7       5     2    5        4           4  6.0000
## 453              7       5     2    5        4           4  6.0000
## 454              7       5     2    5        4           4  6.0000
## 455              7       5     2    5        4           4  6.0000
## 456              7       5     2    5        4           4  6.0000
## 457              7       5     2    5        4           4  6.0000
## 458              7       5     2    5        4           4  6.0000
## 459              7       5     2    5        4           4  6.0000
## 460              7       5     2    5        4           4  6.0000
## 461              7       5     2    5        4           4  6.0000
## 462              7       5     2    5        4           4  6.0000
## 463              6       6     2    3        6           3  9.0000
## 464              6       6     2    3        6           3  9.0000
## 465              6       6     2    3        6           3  9.0000
## 466              6       6     2    3        6           3  9.0000
## 467              6       6     2    3        6           3  9.0000
## 468              6       6     2    3        6           3  9.0000
## 469              6       6     2    3        6           3  9.0000
## 470              6       6     2    3        6           3  9.0000
## 471              6       6     2    3        6           3  9.0000
## 472              6       6     2    3        6           3  9.0000
## 473              6       6     2    3        6           3  9.0000
## 474              6       6     2    3        6           3  9.0000
## 475              4       7     2    5        7           6  8.0000
## 476              4       7     2    5        7           6  8.0000
## 477              4       7     2    5        7           6  8.0000
## 478              4       7     2    5        7           6  8.0000
## 479              4       7     2    5        7           6  8.0000
## 480              4       7     2    5        7           6  8.0000
## 481              4       7     2    5        7           6  8.0000
## 482              4       7     2    5        7           6  8.0000
## 483              4       7     2    5        7           6  8.0000
## 484              4       7     2    5        7           6  8.0000
## 485              4       7     2    5        7           6  8.0000
## 486              4       7     2    5        7           6  8.0000
## 487              5       5     2    5        4           4  7.5000
## 488              5       5     2    5        4           4  7.5000
## 489              5       5     2    5        4           4  7.5000
## 490              5       5     2    5        4           4  7.5000
## 491              5       5     2    5        4           4  7.5000
## 492              5       5     2    5        4           4  7.5000
## 493              5       5     2    5        4           4  7.5000
## 494              5       5     2    5        4           4  7.5000
## 495              5       5     2    5        4           4  7.5000
## 496              5       5     2    5        4           4  7.5000
## 497              5       5     2    5        4           4  7.5000
## 498              5       5     2    5        4           4  7.5000
## 499              7       2     1    7        3           5  6.0000
## 500              7       2     1    7        3           5  6.0000
## 501              7       2     1    7        3           5  6.0000
## 502              7       2     1    7        3           5  6.0000
## 503              7       2     1    7        3           5  6.0000
## 504              7       2     1    7        3           5  6.0000
## 505              7       2     1    7        3           5  6.0000
## 506              7       2     1    7        3           5  6.0000
## 507              7       2     1    7        3           5  6.0000
## 508              7       2     1    7        3           5  6.0000
## 509              7       2     1    7        3           5  6.0000
## 510              7       2     1    7        3           5  6.0000
## 511              5       3     3    3        4           3  7.5000
## 512              5       3     3    3        4           3  7.5000
## 513              5       3     3    3        4           3  7.5000
## 514              5       3     3    3        4           3  7.5000
## 515              5       3     3    3        4           3  7.5000
## 516              5       3     3    3        4           3  7.5000
## 517              5       3     3    3        4           3  7.5000
## 518              5       3     3    3        4           3  7.5000
## 519              5       3     3    3        4           3  7.5000
## 520              5       3     3    3        4           3  7.5000
## 521              5       3     3    3        4           3  7.5000
## 522              5       3     3    3        4           3  7.5000
## 523              4       4     2    4        5           6  6.0000
## 524              4       4     2    4        5           6  6.0000
## 525              4       4     2    4        5           6  6.0000
## 526              4       4     2    4        5           6  6.0000
## 527              4       4     2    4        5           6  6.0000
## 528              4       4     2    4        5           6  6.0000
## 529              4       4     2    4        5           6  6.0000
## 530              4       4     2    4        5           6  6.0000
## 531              4       4     2    4        5           6  6.0000
## 532              4       4     2    4        5           6  6.0000
## 533              4       4     2    4        5           6  6.0000
## 534              4       4     2    4        5           6  6.0000
## 535              5       6     2    3        5           4  9.5000
## 536              5       6     2    3        5           4  9.5000
## 537              5       6     2    3        5           4  9.5000
## 538              5       6     2    3        5           4  9.5000
## 539              5       6     2    3        5           4  9.5000
## 540              5       6     2    3        5           4  9.5000
## 541              5       6     2    3        5           4  9.5000
## 542              5       6     2    3        5           4  9.5000
## 543              5       6     2    3        5           4  9.5000
## 544              5       6     2    3        5           4  9.5000
## 545              5       6     2    3        5           4  9.5000
## 546              5       6     2    3        5           4  9.5000
## 547              6       2     6    7        2           3  9.0000
## 548              6       2     6    7        2           3  9.0000
## 549              6       2     6    7        2           3  9.0000
## 550              6       2     6    7        2           3  9.0000
## 551              6       2     6    7        2           3  9.0000
## 552              6       2     6    7        2           3  9.0000
## 553              6       2     6    7        2           3  9.0000
## 554              6       2     6    7        2           3  9.0000
## 555              6       2     6    7        2           3  9.0000
## 556              6       2     6    7        2           3  9.0000
## 557              6       2     6    7        2           3  9.0000
## 558              6       2     6    7        2           3  9.0000
##     modality stress_group
## 1       fmri      control
## 2       fmri      control
## 3       fmri      control
## 4       fmri      control
## 5       fmri      control
## 6       fmri      control
## 7       fmri      control
## 8       fmri      control
## 9       fmri      control
## 10      fmri      control
## 11      fmri      control
## 12      fmri      control
## 13      fmri      control
## 14      fmri      control
## 15      fmri      control
## 16      fmri      control
## 17      fmri      control
## 18      fmri      control
## 19      fmri      control
## 20      fmri      control
## 21      fmri      control
## 22      fmri      control
## 23      fmri      control
## 24      fmri      control
## 25      fmri      control
## 26      fmri      control
## 27      fmri      control
## 28      fmri      control
## 29      fmri      control
## 30      fmri      control
## 31      fmri      control
## 32      fmri      control
## 33      fmri      control
## 34      fmri      control
## 35      fmri      control
## 36      fmri      control
## 37      fmri      control
## 38      fmri      control
## 39      fmri      control
## 40      fmri      control
## 41      fmri      control
## 42      fmri      control
## 43      fmri      control
## 44      fmri      control
## 45      fmri      control
## 46      fmri      control
## 47      fmri      control
## 48      fmri      control
## 49      fmri      control
## 50      fmri      control
## 51      fmri      control
## 52      fmri      control
## 53      fmri      control
## 54      fmri      control
## 55      fmri      control
## 56      fmri      control
## 57      fmri      control
## 58      fmri      control
## 59      fmri      control
## 60      fmri      control
## 61      fmri      control
## 62      fmri      control
## 63      fmri      control
## 64      fmri      control
## 65      fmri      control
## 66      fmri      control
## 67      fmri      control
## 68      fmri      control
## 69      fmri      control
## 70      fmri      control
## 71      fmri      control
## 72      fmri      control
## 73      fmri      control
## 74      fmri      control
## 75      fmri      control
## 76      fmri      control
## 77      fmri      control
## 78      fmri      control
## 79      fmri      control
## 80      fmri      control
## 81      fmri      control
## 82      fmri      control
## 83      fmri      control
## 84      fmri      control
## 85      fmri      control
## 86      fmri      control
## 87      fmri      control
## 88      fmri      control
## 89      fmri      control
## 90      fmri      control
## 91      fmri      control
## 92      fmri      control
## 93      fmri      control
## 94      fmri      control
## 95      fmri      control
## 96      fmri      control
## 97      fmri      control
## 98      fmri      control
## 99      fmri      control
## 100     fmri      control
## 101     fmri      control
## 102     fmri      control
## 103     fmri      control
## 104     fmri      control
## 105     fmri      control
## 106     fmri      control
## 107     fmri      control
## 108     fmri      control
## 109     fmri      control
## 110     fmri      control
## 111     fmri      control
## 112     fmri      control
## 113     fmri      control
## 114     fmri      control
## 115     fmri      control
## 116     fmri      control
## 117     fmri      control
## 118     fmri      control
## 119     fmri      control
## 120     fmri      control
## 121     fmri      control
## 122     fmri      control
## 123     fmri      control
## 124     fmri      control
## 125     fmri      control
## 126     fmri      control
## 127     fmri      control
## 128     fmri      control
## 129     fmri      control
## 130     fmri      control
## 131     fmri      control
## 132     fmri      control
## 133     fmri      control
## 134     fmri      control
## 135     fmri      control
## 136     fmri      control
## 137     fmri      control
## 138     fmri      control
## 139     fmri      control
## 140     fmri      control
## 141     fmri      control
## 142     fmri      control
## 143     fmri      control
## 144     fmri      control
## 145     fmri      control
## 146     fmri      control
## 147     fmri      control
## 148     fmri      control
## 149     fmri      control
## 150     fmri      control
## 151     fmri      control
## 152     fmri      control
## 153     fmri      control
## 154     fmri      control
## 155     fmri      control
## 156     fmri      control
## 157     fmri      control
## 158     fmri      control
## 159     fmri      control
## 160     fmri      control
## 161     fmri      control
## 162     fmri      control
## 163     fmri      control
## 164     fmri      control
## 165     fmri      control
## 166     fmri      control
## 167     fmri      control
## 168     fmri      control
## 169     fmri      control
## 170     fmri      control
## 171     fmri      control
## 172     fmri      control
## 173     fmri      control
## 174     fmri      control
## 175     fmri      control
## 176     fmri      control
## 177     fmri      control
## 178     fmri      control
## 179     fmri      control
## 180     fmri      control
## 181     fmri      control
## 182     fmri      control
## 183     fmri      control
## 184     fmri      control
## 185     fmri      control
## 186     fmri      control
## 187     fmri      control
## 188     fmri      control
## 189     fmri      control
## 190     fmri      control
## 191     fmri      control
## 192     fmri      control
## 193     fmri      control
## 194     fmri      control
## 195     fmri      control
## 196     fmri      control
## 197     fmri      control
## 198     fmri      control
## 199     fmri      control
## 200     fmri      control
## 201     fmri      control
## 202     fmri      control
## 203     fmri      control
## 204     fmri      control
## 205     fmri      control
## 206     fmri      control
## 207     fmri      control
## 208     fmri      control
## 209     fmri      control
## 210     fmri      control
## 211     fmri      control
## 212     fmri      control
## 213     fmri      control
## 214     fmri      control
## 215     fmri      control
## 216     fmri      control
## 217     fmri      control
## 218     fmri      control
## 219     fmri      control
## 220     fmri      control
## 221     fmri      control
## 222     fmri      control
## 223     fmri      control
## 224     fmri      control
## 225     fmri      control
## 226     fmri      control
## 227     fmri      control
## 228     fmri      control
## 229     fmri      control
## 230     fmri      control
## 231     fmri      control
## 232     fmri      control
## 233     fmri      control
## 234     fmri      control
## 235     fmri      control
## 236     fmri      control
## 237     fmri      control
## 238     fmri      control
## 239     fmri      control
## 240     fmri      control
## 241     fmri      control
## 242     fmri      control
## 243     fmri      control
## 244     fmri      control
## 245     fmri      control
## 246     fmri      control
## 247     fmri      control
## 248     fmri      control
## 249     fmri      control
## 250     fmri      control
## 251     fmri      control
## 252     fmri      control
## 253     fmri      control
## 254     fmri      control
## 255     fmri      control
## 256     fmri      control
## 257     fmri      control
## 258     fmri      control
## 259     fmri      control
## 260     fmri      control
## 261     fmri       stress
## 262     fmri       stress
## 263     fmri       stress
## 264     fmri       stress
## 265     fmri       stress
## 266     fmri       stress
## 267     fmri       stress
## 268     fmri       stress
## 269     fmri       stress
## 270     fmri       stress
## 271     fmri       stress
## 272     fmri       stress
## 273     fmri       stress
## 274     fmri       stress
## 275     fmri       stress
## 276     fmri       stress
## 277     fmri       stress
## 278     fmri       stress
## 279     fmri       stress
## 280     fmri       stress
## 281     fmri       stress
## 282     fmri       stress
## 283     fmri       stress
## 284     fmri       stress
## 285     fmri       stress
## 286     fmri       stress
## 287     fmri       stress
## 288     fmri       stress
## 289     fmri       stress
## 290     fmri       stress
## 291     fmri       stress
## 292     fmri       stress
## 293     fmri       stress
## 294     fmri       stress
## 295     fmri       stress
## 296     fmri       stress
## 297     fmri       stress
## 298     fmri       stress
## 299     fmri       stress
## 300     fmri       stress
## 301     fmri       stress
## 302     fmri       stress
## 303     fmri       stress
## 304     fmri       stress
## 305     fmri       stress
## 306     fmri       stress
## 307     fmri       stress
## 308     fmri       stress
## 309     fmri       stress
## 310     fmri       stress
## 311     fmri       stress
## 312     fmri       stress
## 313     fmri       stress
## 314     fmri       stress
## 315     fmri       stress
## 316     fmri       stress
## 317     fmri       stress
## 318     fmri       stress
## 319     fmri       stress
## 320     fmri       stress
## 321     fmri       stress
## 322     fmri       stress
## 323     fmri       stress
## 324     fmri       stress
## 325     fmri       stress
## 326     fmri       stress
## 327     fmri       stress
## 328     fmri       stress
## 329     fmri       stress
## 330     fmri       stress
## 331     fmri       stress
## 332     fmri       stress
## 333     fmri       stress
## 334     fmri       stress
## 335     fmri       stress
## 336     fmri       stress
## 337     fmri       stress
## 338     fmri       stress
## 339     fmri       stress
## 340     fmri       stress
## 341     fmri       stress
## 342     fmri       stress
## 343     fmri       stress
## 344     fmri       stress
## 345     fmri       stress
## 346     fmri       stress
## 347     fmri       stress
## 348     fmri       stress
## 349     fmri       stress
## 350     fmri       stress
## 351     fmri       stress
## 352     fmri       stress
## 353     fmri       stress
## 354     fmri       stress
## 355     fmri      control
## 356     fmri      control
## 357     fmri      control
## 358     fmri      control
## 359     fmri      control
## 360     fmri      control
## 361     fmri      control
## 362     fmri      control
## 363     fmri      control
## 364     fmri      control
## 365     fmri      control
## 366     fmri      control
## 367     fmri       stress
## 368     fmri       stress
## 369     fmri       stress
## 370     fmri       stress
## 371     fmri       stress
## 372     fmri       stress
## 373     fmri       stress
## 374     fmri       stress
## 375     fmri       stress
## 376     fmri       stress
## 377     fmri       stress
## 378     fmri       stress
## 379     fmri       stress
## 380     fmri       stress
## 381     fmri       stress
## 382     fmri       stress
## 383     fmri       stress
## 384     fmri       stress
## 385     fmri       stress
## 386     fmri       stress
## 387     fmri       stress
## 388     fmri       stress
## 389     fmri       stress
## 390     fmri       stress
## 391     fmri       stress
## 392     fmri       stress
## 393     fmri       stress
## 394     fmri       stress
## 395     fmri       stress
## 396     fmri       stress
## 397     fmri       stress
## 398     fmri       stress
## 399     fmri       stress
## 400     fmri       stress
## 401     fmri       stress
## 402     fmri       stress
## 403     fmri       stress
## 404     fmri       stress
## 405     fmri       stress
## 406     fmri       stress
## 407     fmri       stress
## 408     fmri       stress
## 409     fmri       stress
## 410     fmri       stress
## 411     fmri       stress
## 412     fmri       stress
## 413     fmri       stress
## 414     fmri       stress
## 415     fmri       stress
## 416     fmri       stress
## 417     fmri       stress
## 418     fmri       stress
## 419     fmri       stress
## 420     fmri       stress
## 421     fmri       stress
## 422     fmri       stress
## 423     fmri       stress
## 424     fmri       stress
## 425     fmri       stress
## 426     fmri       stress
## 427     fmri       stress
## 428     fmri       stress
## 429     fmri       stress
## 430     fmri       stress
## 431     fmri       stress
## 432     fmri       stress
## 433     fmri       stress
## 434     fmri       stress
## 435     fmri       stress
## 436     fmri       stress
## 437     fmri       stress
## 438     fmri       stress
## 439     fmri       stress
## 440     fmri       stress
## 441     fmri       stress
## 442     fmri       stress
## 443     fmri       stress
## 444     fmri       stress
## 445     fmri       stress
## 446     fmri       stress
## 447     fmri       stress
## 448     fmri       stress
## 449     fmri       stress
## 450     fmri       stress
## 451     fmri       stress
## 452     fmri       stress
## 453     fmri       stress
## 454     fmri       stress
## 455     fmri       stress
## 456     fmri       stress
## 457     fmri       stress
## 458     fmri       stress
## 459     fmri       stress
## 460     fmri       stress
## 461     fmri       stress
## 462     fmri       stress
## 463     fmri       stress
## 464     fmri       stress
## 465     fmri       stress
## 466     fmri       stress
## 467     fmri       stress
## 468     fmri       stress
## 469     fmri       stress
## 470     fmri       stress
## 471     fmri       stress
## 472     fmri       stress
## 473     fmri       stress
## 474     fmri       stress
## 475     fmri       stress
## 476     fmri       stress
## 477     fmri       stress
## 478     fmri       stress
## 479     fmri       stress
## 480     fmri       stress
## 481     fmri       stress
## 482     fmri       stress
## 483     fmri       stress
## 484     fmri       stress
## 485     fmri       stress
## 486     fmri       stress
## 487     fmri       stress
## 488     fmri       stress
## 489     fmri       stress
## 490     fmri       stress
## 491     fmri       stress
## 492     fmri       stress
## 493     fmri       stress
## 494     fmri       stress
## 495     fmri       stress
## 496     fmri       stress
## 497     fmri       stress
## 498     fmri       stress
## 499     fmri       stress
## 500     fmri       stress
## 501     fmri       stress
## 502     fmri       stress
## 503     fmri       stress
## 504     fmri       stress
## 505     fmri       stress
## 506     fmri       stress
## 507     fmri       stress
## 508     fmri       stress
## 509     fmri       stress
## 510     fmri       stress
## 511     fmri       stress
## 512     fmri       stress
## 513     fmri       stress
## 514     fmri       stress
## 515     fmri       stress
## 516     fmri       stress
## 517     fmri       stress
## 518     fmri       stress
## 519     fmri       stress
## 520     fmri       stress
## 521     fmri       stress
## 522     fmri       stress
## 523     fmri       stress
## 524     fmri       stress
## 525     fmri       stress
## 526     fmri       stress
## 527     fmri       stress
## 528     fmri       stress
## 529     fmri       stress
## 530     fmri       stress
## 531     fmri       stress
## 532     fmri       stress
## 533     fmri       stress
## 534     fmri       stress
## 535     fmri       stress
## 536     fmri       stress
## 537     fmri       stress
## 538     fmri       stress
## 539     fmri       stress
## 540     fmri       stress
## 541     fmri       stress
## 542     fmri       stress
## 543     fmri       stress
## 544     fmri       stress
## 545     fmri       stress
## 546     fmri       stress
## 547     fmri       stress
## 548     fmri       stress
## 549     fmri       stress
## 550     fmri       stress
## 551     fmri       stress
## 552     fmri       stress
## 553     fmri       stress
## 554     fmri       stress
## 555     fmri       stress
## 556     fmri       stress
## 557     fmri       stress
## 558     fmri       stress

## # A tibble: 2 x 2
##          group `n()`
##         <fctr> <int>
## 1 control-fmri    23
## 2  stress-fmri    24
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## adjustedRating ~ subScaleName * group * shockCond + (1 + subScaleName *  
##     shockCond | subid)
##    Data: d_val
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 1103.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.2399 -0.5895 -0.0305  0.5562  3.2341 
## 
## Random effects:
##  Groups   Name                     Variance Std.Dev. Corr             
##  subid    (Intercept)              0.156649 0.39579                   
##           subScaleName1            0.141987 0.37681  -0.52            
##           shockCond1               0.003978 0.06307   0.13 -0.42      
##           subScaleName1:shockCond1 0.013973 0.11821   0.38 -0.11 -0.82
##  Residual                          0.280223 0.52936                   
## Number of obs: 558, groups:  subid, 47
## 
## Fixed effects:
##                                 Estimate Std. Error       df t value
## (Intercept)                      2.48546    0.06195 44.98000  40.120
## subScaleName1                    0.25591    0.05938 44.85000   4.310
## group1                          -0.04575    0.06195 44.98000  -0.738
## shockCond1                       0.06393    0.02425 84.91000   2.636
## subScaleName1:group1            -0.15614    0.05938 44.85000  -2.629
## subScaleName1:shockCond1        -0.12646    0.02831 47.72000  -4.468
## group1:shockCond1                0.02509    0.02425 84.91000   1.035
## subScaleName1:group1:shockCond1 -0.10363    0.02831 47.72000  -3.661
##                                 Pr(>|t|)    
## (Intercept)                      < 2e-16 ***
## subScaleName1                   8.82e-05 ***
## group1                          0.464083    
## shockCond1                      0.009973 ** 
## subScaleName1:group1            0.011674 *  
## subScaleName1:shockCond1        4.85e-05 ***
## group1:shockCond1               0.303805    
## subScaleName1:group1:shockCond1 0.000627 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) sbScN1 group1 shckC1 sbSN1:1 sSN1:C gr1:C1
## subScaleNm1 -0.446                                           
## group1      -0.022  0.010                                    
## shockCond1   0.046 -0.148  0.000                             
## sbSclNm1:g1  0.010 -0.022 -0.446  0.003                      
## sbSclNm1:C1  0.213 -0.063 -0.005 -0.190  0.003               
## grp1:shckC1  0.000  0.003  0.046 -0.025 -0.148   0.004       
## sbScN1:1:C1 -0.005  0.003  0.213  0.004 -0.063  -0.024 -0.190
## Source: local data frame [282 x 6]
## Groups: subScaleName, shockCond [6]
## 
## # A tibble: 282 x 6
##      group study subScaleName shockCond  subid adjustedRating
##      <chr> <chr>       <fctr>    <fctr> <fctr>          <dbl>
##  1 Control  fmri      Arousal      safe  ap100       1.500000
##  2 Control  fmri      Arousal      safe  ap101       3.333333
##  3 Control  fmri      Arousal      safe  ap102       3.000000
##  4 Control  fmri      Arousal      safe  ap103       1.666667
##  5 Control  fmri      Arousal      safe  ap104       2.000000
##  6 Control  fmri      Arousal      safe  ap105       2.666667
##  7 Control  fmri      Arousal      safe  ap106       3.333333
##  8 Control  fmri      Arousal      safe  ap107       2.000000
##  9 Control  fmri      Arousal      safe  ap108       1.666667
## 10 Control  fmri      Arousal      safe  ap109       2.333333
## # ... with 272 more rows
## Source: local data frame [12 x 7]
## Groups: group, subScaleName [?]
## 
## # A tibble: 12 x 7
##      group subScaleName shockCond     n     mean        sd         se
##      <chr>       <fctr>    <fctr> <int>    <dbl>     <dbl>      <dbl>
##  1 Control      Arousal      safe    23 2.268116 0.6566273 0.13691626
##  2 Control      Arousal    threat    23 2.405797 0.7518094 0.15676310
##  3 Control     Negative      safe    23 2.057971 0.7547973 0.15738611
##  4 Control     Negative    threat    23 2.181159 0.6925160 0.14439957
##  5 Control     Positive      safe    23 2.923913 0.3980009 0.08298892
##  6 Control     Positive    threat    23 2.960145 0.4050421 0.08445711
##  7  Stress      Arousal      safe    24 1.986111 0.6701299 0.13678969
##  8  Stress      Arousal    threat    24 2.791667 0.7601964 0.15517444
##  9  Stress     Negative      safe    24 2.020833 0.7853005 0.16029879
## 10  Stress     Negative    threat    24 2.652778 0.8059511 0.16451408
## 11  Stress     Positive      safe    24 2.680556 0.5426644 0.11077092
## 12  Stress     Positive    threat    24 2.402778 0.5771759 0.11781554

## Warning: Ignoring unknown aesthetics: y

head(d_val)
##   subid BAS.D BAS.F BAS.W      BIS  SMM TraitAnx        group run
## 1 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   1
## 2 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   1
## 3 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   2
## 4 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   2
## 5 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   4
## 6 ap100   3.5  3.75   3.2 3.714286 2.75      2.8 control-fmri   4
##   shockCond subScaleName adjustedRating  respRT remove good_math
## 1      safe     Negative            1.5 3.91895     NA         5
## 2      safe     Positive            2.5 3.09475     NA         5
## 3    threat     Negative            2.5 1.32142     NA         5
## 4    threat     Positive            2.5 3.32340     NA         5
## 5    threat     Negative            2.0 3.21695     NA         5
## 6    threat     Positive            2.5 1.80115     NA         5
##   important_math anxious happy safe stressed life_stress sleep modality
## 1              6       3     2    3        3           4   4.5     fmri
## 2              6       3     2    3        3           4   4.5     fmri
## 3              6       3     2    3        3           4   4.5     fmri
## 4              6       3     2    3        3           4   4.5     fmri
## 5              6       3     2    3        3           4   4.5     fmri
## 6              6       3     2    3        3           4   4.5     fmri
##   stress_group
## 1      control
## 2      control
## 3      control
## 4      control
## 5      control
## 6      control
data = d_val %>% group_by(subid, group, subScaleName, shockCond) %>%
  summarise(adjustedRating = mean(adjustedRating))

# control diff?
bartlett.test(adjustedRating ~ shockCond, data=data[(data$subScaleName == 'Negative') &
                                                    (data$group == 'control-fmri'),])
## 
##  Bartlett test of homogeneity of variances
## 
## data:  adjustedRating by shockCond
## Bartlett's K-squared = 0.15934, df = 1, p-value = 0.6898
t.test(adjustedRating ~ shockCond, data=data[(data$subScaleName == 'Negative') &
                                               (data$group == 'control-fmri'),], 
       paired=T, var.equal=TRUE)
## 
##  Paired t-test
## 
## data:  adjustedRating by shockCond
## t = -1.6931, df = 22, p-value = 0.1046
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.27408260  0.02770578
## sample estimates:
## mean of the differences 
##              -0.1231884
bartlett.test(adjustedRating ~ shockCond, data=data[(data$subScaleName == 'Positive') &
                                                    (data$group == 'control-fmri'),])
## 
##  Bartlett test of homogeneity of variances
## 
## data:  adjustedRating by shockCond
## Bartlett's K-squared = 0.0066151, df = 1, p-value = 0.9352
t.test(adjustedRating ~ shockCond, data=data[(data$subScaleName == 'Positive') &
                                               (data$group == 'control-fmri'),], 
       paired=T, var.equal=TRUE)
## 
##  Paired t-test
## 
## data:  adjustedRating by shockCond
## t = -0.63983, df = 22, p-value = 0.5289
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.15367041  0.08120664
## sample estimates:
## mean of the differences 
##             -0.03623188
# stress diff?
bartlett.test(adjustedRating ~ shockCond, data=data[(data$subScaleName == 'Negative') &
                                                    (data$group == 'stress-fmri'),])
## 
##  Bartlett test of homogeneity of variances
## 
## data:  adjustedRating by shockCond
## Bartlett's K-squared = 0.015165, df = 1, p-value = 0.902
t.test(adjustedRating ~ shockCond, data=data[(data$subScaleName == 'Negative') &
                                               (data$group == 'stress-fmri'),], 
       paired=T, var.equal=TRUE)
## 
##  Paired t-test
## 
## data:  adjustedRating by shockCond
## t = -4.4433, df = 23, p-value = 0.0001864
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.9261551 -0.3377338
## sample estimates:
## mean of the differences 
##              -0.6319444
bartlett.test(adjustedRating ~ shockCond, data=data[(data$subScaleName == 'Positive') &
                                                    (data$group == 'stress-fmri'),])
## 
##  Bartlett test of homogeneity of variances
## 
## data:  adjustedRating by shockCond
## Bartlett's K-squared = 0.085519, df = 1, p-value = 0.77
t.test(adjustedRating ~ shockCond, data=data[(data$subScaleName == 'Positive') &
                                               (data$group == 'stress-fmri'),], 
       paired=T, var.equal=TRUE)
## 
##  Paired t-test
## 
## data:  adjustedRating by shockCond
## t = 2.5103, df = 23, p-value = 0.01955
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.04886574 0.50668981
## sample estimates:
## mean of the differences 
##               0.2777778
# other
bartlett.test(adjustedRating ~ group, data=data[(data$subScaleName == 'Negative') & 
                                            (data$shockCond == 'threat'),])
## 
##  Bartlett test of homogeneity of variances
## 
## data:  adjustedRating by group
## Bartlett's K-squared = 0.50317, df = 1, p-value = 0.4781
t.test(adjustedRating ~ group, data=data[(data$subScaleName == 'Negative') & 
                                            (data$shockCond == 'threat'),], var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  adjustedRating by group
## t = -2.1475, df = 45, p-value = 0.03718
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.91394633 -0.02929038
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.181159                   2.652778
t.test(adjustedRating ~ group, data=data[(data$subScaleName == 'Negative') & 
                                            (data$shockCond == 'safe'),], var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  adjustedRating by group
## t = 0.16517, df = 45, p-value = 0.8695
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.4157136  0.4899890
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.057971                   2.020833
t.test(adjustedRating ~ group, data=data[(data$subScaleName == 'Positive') & 
                                            (data$shockCond == 'threat'),], var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  adjustedRating by group
## t = 3.8166, df = 45, p-value = 0.0004106
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.2632349 0.8514994
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.960145                   2.402778
t.test(adjustedRating ~ group, data=data[(data$subScaleName == 'Positive') & 
                                            (data$shockCond == 'safe'),], var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  adjustedRating by group
## t = 1.7468, df = 45, p-value = 0.0875
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.0372423  0.5239573
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.923913                   2.680556

Do ratings on in-scanner arousal questionnaires differ between groups?

## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: adjustedRating ~ group * shockCond + (1 + shockCond | subid)
##    Data: d_aro
## 
## REML criterion at convergence: 666.7
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.47918 -0.49308 -0.06321  0.59289  2.64093 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr
##  subid    (Intercept) 0.33299  0.5771       
##           shockCond1  0.01487  0.1219   0.41
##  Residual             0.45112  0.6717       
## Number of obs: 279, groups:  subid, 47
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)        2.36782    0.09332 44.71000  25.372  < 2e-16 ***
## group1             0.02531    0.09332 44.71000   0.271 0.787481    
## shockCond1         0.23997    0.04402 43.74000   5.451 2.18e-06 ***
## group1:shockCond1  0.16705    0.04402 43.74000   3.795 0.000451 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1
## group1      -0.022              
## shockCond1   0.151 -0.002       
## grp1:shckC1 -0.002  0.151 -0.025
## 
##  Bartlett test of homogeneity of variances
## 
## data:  adjustedRating by group
## Bartlett's K-squared = 0.0027071, df = 1, p-value = 0.9585
## 
##  Two Sample t-test
## 
## data:  adjustedRating by group
## t = -1.749, df = 45, p-value = 0.08712
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.83023965  0.05850052
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.405797                   2.791667
## 
##  Bartlett test of homogeneity of variances
## 
## data:  adjustedRating by group
## Bartlett's K-squared = 0.0091116, df = 1, p-value = 0.924
## 
##  Two Sample t-test
## 
## data:  adjustedRating by group
## t = 1.4564, df = 45, p-value = 0.1522
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1079760  0.6719857
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.268116                   1.986111
## 
##  Bartlett test of homogeneity of variances
## 
## data:  adjustedRating by shockCond
## Bartlett's K-squared = 0.39297, df = 1, p-value = 0.5307
## 
##  Paired t-test
## 
## data:  adjustedRating by shockCond
## t = -1.3097, df = 22, p-value = 0.2038
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.35569408  0.08033176
## sample estimates:
## mean of the differences 
##              -0.1376812
## 
##  Bartlett test of homogeneity of variances
## 
## data:  adjustedRating by shockCond
## Bartlett's K-squared = 0.35703, df = 1, p-value = 0.5502
## 
##  Paired t-test
## 
## data:  adjustedRating by shockCond
## t = -5.6265, df = 23, p-value = 9.998e-06
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.1017267 -0.5093844
## sample estimates:
## mean of the differences 
##              -0.8055556

Do ratings on post-test valence questionnaires differ between groups?

##   X subid        group gender remove anxious happy safe stressed
## 1 0 ap100 control-fmri   male     NA       3     2    3        3
## 2 1 ap101 control-fmri   male     NA       2     5    6        2
## 3 2 ap102 control-fmri   male     NA       4     2    5        5
## 4 3 ap103 control-fmri   male     NA       2     3    5        2
## 5 4 ap104 control-fmri   male     NA       3     5    6        3
## 6 5 ap105 control-fmri   male     NA       6     2    5        6
##   life_stress sleep net_neg negative positive
## 1           4   4.5       1      3.0      2.5
## 2           2   8.5      -7      2.0      5.5
## 3           4   9.0       2      4.5      3.5
## 4           2   6.5      -4      2.0      4.0
## 5           4   8.0      -5      3.0      5.5
## 6           3   8.0       5      6.0      3.5
## [1] 94 14
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: emo_rating ~ scale * group + (1 | subid)
##    Data: d_ratings_long
## 
## REML criterion at convergence: 307.5
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.84661 -0.61228  0.01801  0.63648  2.50316 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.000    0.000   
##  Residual             1.457    1.207   
## Number of obs: 94, groups:  subid, 47
## 
## Fixed effects:
##               Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)     3.7939     0.1245 90.0000  30.464  < 2e-16 ***
## scale1          0.1902     0.1245 90.0000   1.527 0.130173    
## group1          0.1852     0.1245 90.0000   1.487 0.140410    
## scale1:group1  -0.4402     0.1245 90.0000  -3.535 0.000647 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) scale1 group1
## scale1       0.000              
## group1      -0.021  0.000       
## scale1:grp1  0.000 -0.021  0.000
## 
##  Bartlett test of homogeneity of variances
## 
## data:  negative by group
## Bartlett's K-squared = 0.00099777, df = 1, p-value = 0.9748
## 
##  Two Sample t-test
## 
## data:  negative by group
## t = -3.2618, df = 45, p-value = 0.002115
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -2.0233118 -0.4784998
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.978261                   4.229167
## 
##  Bartlett test of homogeneity of variances
## 
## data:  positive by group
## Bartlett's K-squared = 0.020551, df = 1, p-value = 0.886
## 
##  Two Sample t-test
## 
## data:  positive by group
## t = 1.604, df = 45, p-value = 0.1157
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1303968  1.1503243
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   4.239130                   3.729167
##   mean(safe)
## 1    5.06383
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Post-test affective ratings, we observed an interaction between group and valence, F(1,90)=12.4948, p < 0.001, such that participants rated feeling significantly more negative (stressed, anxious), t(45) = 3.2618, p < 0.01. Positive ratings (safe, happy) did not significantly differ between groups (p > 0.1).

1) Stress effects on memory

Load in data

# note that shock and post trials are filtered out
dtest = read.csv('/Volumes/group/awagner/sgagnon/AP/data/behav/df_test.csv')
with(dtest %>% filter(acc =='H', conf == 'Hi'), table(subid))
## subid
## ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ap109 ap110 ap111 
##    89   105    68   113   147   119    29   125    29    61    20    73 
## ap113 ap114 ap115 ap116 ap117 ap118 ap119 ap120 ap121 ap122 ap150 ap151 
##    75   102    78   148    85    63   115    75    34    97    66     3 
## ap152 ap153 ap154 ap155 ap156 ap157 ap158 ap159 ap160 ap161 ap162 ap163 
##    44    33    46    38     5    53    11    51    51    27    44   107 
## ap164 ap165 ap166 ap167 ap168 ap169 ap170 ap171 ap172 ap173 ap174 
##    82    65    72    39    46    71    74    33    21     8    85
with(dtest, table(acc, conf))
##              conf
## acc             Hi   Lo    N
##   CR             0    0 2475
##   FA           216 1110    0
##   H           3025 1448    0
##   M              0    0 1109
##   no response    0    0  140
##   SM           706 1279    0
head(dtest)
##   X run trial   onset duration shockCond  target      associate    resp
## 1 0   1     1 12.0191  10.6661      safe  BANDIT       cemetery  indoor
## 2 1   1     2 22.7129   9.1242      safe  WALRUS           foil    foil
## 3 2   1     3 31.8642   9.4224      safe  VIOLIN    throne_room  indoor
## 4 3   1     4 41.3132  11.3389      safe   MEDAL       hayfield outdoor
## 5 4   1     5 52.6786   9.7644      safe  MANURE         canyon outdoor
## 6 5   1     6 62.4701   9.1180      safe SARDINE mountain_snowy outdoor
##   acc accSpec respRT subid        group gender remove anxious happy safe
## 1  SM  SMO_Hi 2.1094 ap100 control-fmri   male     NA       3     2    3
## 2  CR      CR 1.7773 ap100 control-fmri   male     NA       3     2    3
## 3   H   HI_Hi 1.6804 ap100 control-fmri   male     NA       3     2    3
## 4   H   HO_Hi 1.7268 ap100 control-fmri   male     NA       3     2    3
## 5   H   HO_Hi 1.3734 ap100 control-fmri   male     NA       3     2    3
## 6   H   HO_Hi 2.1476 ap100 control-fmri   male     NA       3     2    3
##   stressed life_stress sleep net_neg neg pos negative positive cond_orig
## 1        3           4   4.5       1   3 2.5        3      2.5      TO_4
## 2        3           4   4.5       1   3 2.5        3      2.5       F_0
## 3        3           4   4.5       1   3 2.5        3      2.5      TI_2
## 4        3           4   4.5       1   3 2.5        3      2.5      TO_2
## 5        3           4   4.5       1   3 2.5        3      2.5      TO_2
## 6        3           4   4.5       1   3 2.5        3      2.5      TO_4
##      cond reps conf stress_group modality
## 1 outdoor    4   Hi      control     fmri
## 2    foil    0    N      control     fmri
## 3  indoor    2   Hi      control     fmri
## 4 outdoor    2   Hi      control     fmri
## 5 outdoor    2   Hi      control     fmri
## 6 outdoor    4   Hi      control     fmri
with(dtest, table(acc, cond, resp))
## , , resp = foil
## 
##              cond
## acc           foil indoor outdoor
##   CR          2475      0       0
##   FA             0      0       0
##   H              0      0       0
##   M              0    575     534
##   no response    0      0       0
##   SM             0      0       0
## 
## , , resp = indoor
## 
##              cond
## acc           foil indoor outdoor
##   CR             0      0       0
##   FA           715      0       0
##   H              0   2220       0
##   M              0      0       0
##   no response    0      0       0
##   SM             0      0     981
## 
## , , resp = no response
## 
##              cond
## acc           foil indoor outdoor
##   CR             0      0       0
##   FA             0      0       0
##   H              0      0       0
##   M              0      0       0
##   no response   51     45      44
##   SM             0      0       0
## 
## , , resp = outdoor
## 
##              cond
## acc           foil indoor outdoor
##   CR             0      0       0
##   FA           611      0       0
##   H              0      0    2253
##   M              0      0       0
##   no response    0      0       0
##   SM             0   1004       0
# Some processing to label HC associative hits, and objectively old/new status
dtest = dtest %>%
  mutate(group = stress_group) %>%
  dplyr::select(subid, group, run, trial, cond, 
                shockCond, resp, acc, respRT, reps, conf) %>%
  mutate(subj_status = ifelse(resp == 'foil', 
                              'new', 
                              ifelse(resp %in% c('indoor', 'outdoor'),
                                     'old', 
                                     'no response')),
         acc_num = ifelse(acc %in% c('H', 'CR'), 1, 0),
         acc_SH_num = ifelse(acc %in% c('H', 'CR'), 1, 0),
         acc_SH_num = replace(acc_SH_num, conf=='Lo', 0),
         obj_status = ifelse(cond == 'foil', 'new', 'old'))
# str(dtest)
head(dtest)
##   subid   group run trial    cond shockCond    resp acc respRT reps conf
## 1 ap100 control   1     1 outdoor      safe  indoor  SM 2.1094    4   Hi
## 2 ap100 control   1     2    foil      safe    foil  CR 1.7773    0    N
## 3 ap100 control   1     3  indoor      safe  indoor   H 1.6804    2   Hi
## 4 ap100 control   1     4 outdoor      safe outdoor   H 1.7268    2   Hi
## 5 ap100 control   1     5 outdoor      safe outdoor   H 1.3734    2   Hi
## 6 ap100 control   1     6 outdoor      safe outdoor   H 2.1476    4   Hi
##   subj_status acc_num acc_SH_num obj_status
## 1         old       0          0        old
## 2         new       1          1        new
## 3         old       1          1        old
## 4         old       1          1        old
## 5         old       1          1        old
## 6         old       1          1        old
dtest %>% filter(subid == 'ap160', run == 5, trial == 13) # make sure tossed (2 shocks in a row, so shock_and_post == 2)
##  [1] subid       group       run         trial       cond       
##  [6] shockCond   resp        acc         respRT      reps       
## [11] conf        subj_status acc_num     acc_SH_num  obj_status 
## <0 rows> (or 0-length row.names)
with(dtest, table(acc_num, conf))
##        conf
## acc_num   Hi   Lo    N
##       0  922 2389 1249
##       1 3025 1448 2475
with(dtest, table(acc_SH_num, conf, acc))
## , , acc = CR
## 
##           conf
## acc_SH_num   Hi   Lo    N
##          0    0    0    0
##          1    0    0 2475
## 
## , , acc = FA
## 
##           conf
## acc_SH_num   Hi   Lo    N
##          0  216 1110    0
##          1    0    0    0
## 
## , , acc = H
## 
##           conf
## acc_SH_num   Hi   Lo    N
##          0    0 1448    0
##          1 3025    0    0
## 
## , , acc = M
## 
##           conf
## acc_SH_num   Hi   Lo    N
##          0    0    0 1109
##          1    0    0    0
## 
## , , acc = no response
## 
##           conf
## acc_SH_num   Hi   Lo    N
##          0    0    0  140
##          1    0    0    0
## 
## , , acc = SM
## 
##           conf
## acc_SH_num   Hi   Lo    N
##          0  706 1279    0
##          1    0    0    0
str(dtest)
## 'data.frame':    11508 obs. of  15 variables:
##  $ subid      : Factor w/ 47 levels "ap100","ap101",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ group      : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ run        : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ trial      : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ cond       : Factor w/ 3 levels "foil","indoor",..: 3 1 2 3 3 3 1 2 2 1 ...
##  $ shockCond  : Factor w/ 2 levels "safe","threat": 1 1 1 1 1 1 1 1 1 1 ...
##  $ resp       : Factor w/ 4 levels "foil","indoor",..: 2 1 2 4 4 4 1 1 1 1 ...
##  $ acc        : Factor w/ 6 levels "CR","FA","H",..: 6 1 3 3 3 3 1 4 4 1 ...
##  $ respRT     : num  2.11 1.78 1.68 1.73 1.37 ...
##  $ reps       : int  4 0 2 2 2 4 0 4 2 0 ...
##  $ conf       : Factor w/ 3 levels "Hi","Lo","N": 1 3 1 1 1 1 3 3 3 3 ...
##  $ subj_status: chr  "old" "new" "old" "old" ...
##  $ acc_num    : num  0 1 1 1 1 1 1 0 0 1 ...
##  $ acc_SH_num : num  0 1 1 1 1 1 1 0 0 1 ...
##  $ obj_status : chr  "old" "new" "old" "old" ...

1a) Recognition: dprime

Calculate dprime

# get obj counts
obj_counts = dtest %>% group_by(subid, group, reps, shockCond, obj_status) %>%
  summarise(count = n()) %>%
  rename(trial_type = obj_status) %>%
  ungroup()
unique(dtest$acc)
## [1] SM          CR          H           M           FA          no response
## Levels: CR FA H M no response SM
# get counts by bin
coded_counts = dtest %>% 
  filter(acc %in% c('H', 'SM', 'FA')) %>%
  mutate(acc = ifelse(acc == 'FA', 'fa', 'hit')) %>%
  group_by(subid, group, reps, shockCond, acc) %>%
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), shockCond, nesting(reps, acc), 
           fill = list(count = 0))

# combine hits and olds
d_old = coded_counts %>% filter(acc == 'hit') %>%
  dplyr::select(-acc) %>%
  rename(hits = count) %>%
  right_join(obj_counts %>% 
              filter(trial_type == 'old') %>%
              dplyr::select(-trial_type) %>% 
              rename(olds = count))
## Joining, by = c("subid", "group", "shockCond", "reps")
# combine fas and news
d_new= coded_counts %>% filter(acc == 'fa') %>%
  dplyr::select(-acc) %>%
  rename(fas = count) %>%
  right_join(obj_counts %>% 
              filter(trial_type == 'new') %>%
              dplyr::select(-trial_type) %>% 
              rename(news = count)) %>%
  dplyr::select(-reps)
## Joining, by = c("subid", "group", "shockCond", "reps")
# compute hit/fa rates, and other
dmerge = d_old %>% left_join(d_new) %>%
  mutate(hitRate = hits/olds,
         faRate = fas/news,
         halfHit = 0.5/olds,
         halfFA = 0.5/news,
         crRate = 1-faRate,
         reps = factor(reps))
## Joining, by = c("subid", "group", "shockCond")
# get summary stats, before adjusting for 0s/1s
dmerge %>% 
  group_by(subid, group) %>%
  summarise(hitRate = mean(hitRate), 
            faRate = mean(faRate), 
            crRate = mean(crRate)) %>%
  group_by(group) %>%
  summarise_each(funs(mean, std.error, length))
## Warning in mean.default(structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, :
## argument is not numeric or logical: returning NA
## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA
## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.
## # A tibble: 2 x 13
##     group subid_mean hitRate_mean faRate_mean crRate_mean subid_std.error
##    <fctr>      <lgl>        <dbl>       <dbl>       <dbl>           <dbl>
## 1 control         NA    0.8794949   0.3289757   0.6710243        1.571244
## 2  stress         NA    0.8095500   0.3618958   0.6381042        1.524755
## # ... with 7 more variables: hitRate_std.error <dbl>,
## #   faRate_std.error <dbl>, crRate_std.error <dbl>, subid_length <int>,
## #   hitRate_length <int>, faRate_length <int>, crRate_length <int>
dmerge %>% 
  group_by(subid, group, shockCond) %>%
  summarise(hitRate = mean(hitRate), 
            faRate = mean(faRate), 
            crRate = mean(crRate)) %>%
  group_by(group, shockCond) %>%
  summarise_each(funs(mean, std.error, length))
## Warning in mean.default(structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, :
## argument is not numeric or logical: returning NA
## Warning in mean.default(structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, :
## argument is not numeric or logical: returning NA
## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA

## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA
## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.
## Source: local data frame [4 x 14]
## Groups: group [?]
## 
## # A tibble: 4 x 14
##     group shockCond subid_mean hitRate_mean faRate_mean crRate_mean
##    <fctr>    <fctr>      <lgl>        <dbl>       <dbl>       <dbl>
## 1 control      safe         NA    0.8763558   0.3303117   0.6696883
## 2 control    threat         NA    0.8826339   0.3276398   0.6723602
## 3  stress      safe         NA    0.8146807   0.3660714   0.6339286
## 4  stress    threat         NA    0.8044194   0.3577201   0.6422799
## # ... with 8 more variables: subid_std.error <dbl>,
## #   hitRate_std.error <dbl>, faRate_std.error <dbl>,
## #   crRate_std.error <dbl>, subid_length <int>, hitRate_length <int>,
## #   faRate_length <int>, crRate_length <int>
# replace 0 and 1s
dmerge = dmerge %>% mutate(faRate=ifelse(faRate==0, halfFA, faRate),
                  faRate=ifelse(faRate==1, 1-halfFA, faRate),
                  hitRate=ifelse(hitRate==0, halfHit, hitRate),
                  hitRate=ifelse(hitRate==1, 1-halfHit, hitRate))

# calc SDT measures
dmerge = dmerge %>% mutate(dprime = qnorm(hitRate) - qnorm(faRate),
                  c = -(qnorm(hitRate) + qnorm(faRate))/2) %>%
  mutate(reps = factor(reps))

dmerge %>%
  group_by(subid, group) %>%
  summarise(n()) %>%
  group_by(group) %>%
  summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    23
## 2  stress    24
dmerge %>%
  group_by(subid, group) %>%
  summarise(dprime = mean(dprime),
            c = mean(c)) %>%
  group_by(group) %>%
  summarise_each(funs(mean, std.error, length))
## Warning in mean.default(structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, :
## argument is not numeric or logical: returning NA
## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA
## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.
## # A tibble: 2 x 10
##     group subid_mean dprime_mean     c_mean subid_std.error
##    <fctr>      <lgl>       <dbl>      <dbl>           <dbl>
## 1 control         NA    1.894499 -0.3827985        1.571244
## 2  stress         NA    1.478735 -0.2995141        1.524755
## # ... with 5 more variables: dprime_std.error <dbl>, c_std.error <dbl>,
## #   subid_length <int>, dprime_length <int>, c_length <int>
dmerge %>%
  group_by(subid, group, shockCond) %>%
  summarise(dprime = mean(dprime),
            c = mean(c)) %>%
  group_by(group, shockCond) %>%
  summarise_each(funs(mean, std.error, length))
## Warning in mean.default(structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, :
## argument is not numeric or logical: returning NA
## Warning in mean.default(structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, :
## argument is not numeric or logical: returning NA
## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA

## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA
## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

## Warning in var(if (is.vector(x) || is.factor(x)) x else as.double(x), na.rm = na.rm): Calling var(x) on a factor x is deprecated and will become an error.
##   Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.
## Source: local data frame [4 x 11]
## Groups: group [?]
## 
## # A tibble: 4 x 11
##     group shockCond subid_mean dprime_mean     c_mean subid_std.error
##    <fctr>    <fctr>      <lgl>       <dbl>      <dbl>           <dbl>
## 1 control      safe         NA    1.868164 -0.3664629        1.571244
## 2 control    threat         NA    1.920834 -0.3991342        1.571244
## 3  stress      safe         NA    1.493970 -0.3106890        1.524755
## 4  stress    threat         NA    1.463500 -0.2883392        1.524755
## # ... with 5 more variables: dprime_std.error <dbl>, c_std.error <dbl>,
## #   subid_length <int>, dprime_length <int>, c_length <int>
item_d = dmerge

Dprime stats

dmerge %>%
  group_by(subid, group) %>%
  summarise(n()) %>%
  group_by(group) %>%
  summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    23
## 2  stress    24
contrasts(dmerge$group) = c(1,-1)
contrasts(dmerge$shockCond) = c(1,-1)
contrasts(dmerge$reps) = c(-1,1)
summary(lmer(dprime ~ group * shockCond * reps + 
               (1 + shockCond + reps| subid), data=dmerge)) #not enough obs for interaction RE
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## dprime ~ group * shockCond * reps + (1 + shockCond + reps | subid)
##    Data: dmerge
## 
## REML criterion at convergence: 293.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.4575 -0.4637 -0.0290  0.4703  1.7739 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr       
##  subid    (Intercept) 0.54907  0.7410              
##           shockCond1  0.03654  0.1912   -0.03      
##           reps1       0.02114  0.1454    0.35 -0.09
##  Residual             0.05439  0.2332              
## Number of obs: 188, groups:  subid, 47
## 
## Fixed effects:
##                          Estimate Std. Error        df t value Pr(>|t|)
## (Intercept)              1.686617   0.109440 45.000000  15.411  < 2e-16
## group1                   0.207882   0.109440 45.000000   1.900   0.0639
## shockCond1              -0.005550   0.032669 45.000000  -0.170   0.8659
## reps1                    0.207302   0.027192 45.000000   7.624 1.22e-09
## group1:shockCond1       -0.020785   0.032669 45.000000  -0.636   0.5279
## group1:reps1            -0.014628   0.027192 45.000000  -0.538   0.5932
## shockCond1:reps1         0.017423   0.017012 45.000000   1.024   0.3112
## group1:shockCond1:reps1  0.005108   0.017012 45.000000   0.300   0.7654
##                            
## (Intercept)             ***
## group1                  .  
## shockCond1                 
## reps1                   ***
## group1:shockCond1          
## group1:reps1               
## shockCond1:reps1           
## group1:shockCond1:reps1    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1 reps1  gr1:C1 grp1:1 shC1:1
## group1       0.021                                          
## shockCond1  -0.022  0.000                                   
## reps1        0.268  0.006 -0.062                            
## grp1:shckC1  0.000 -0.022  0.021 -0.001                     
## group1:rps1  0.006  0.268 -0.001  0.021 -0.062              
## shckCnd1:r1  0.000  0.000  0.000  0.000  0.000  0.000       
## grp1:shC1:1  0.000  0.000  0.000  0.000  0.000  0.000  0.021
# effect of shockCond within stress:
summary(lmer(dprime ~ shockCond * reps + 
               (1 + shockCond + reps| subid), data=dmerge %>% filter(group == 'stress')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: dprime ~ shockCond * reps + (1 + shockCond + reps | subid)
##    Data: dmerge %>% filter(group == "stress")
## 
## REML criterion at convergence: 124.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.61905 -0.45463  0.05425  0.44985  1.73294 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr     
##  subid    (Intercept) 0.33629  0.5799            
##           shockCond1  0.04069  0.2017   0.41     
##           reps1       0.01088  0.1043   0.68 0.77
##  Residual             0.05904  0.2430            
## Number of obs: 96, groups:  subid, 24
## 
## Fixed effects:
##                  Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)       1.47873    0.12094 23.00000  12.227 1.52e-11 ***
## shockCond1        0.01523    0.04807 23.00000   0.317    0.754    
## reps1             0.22193    0.03269 23.00000   6.789 6.34e-07 ***
## shockCond1:reps1  0.01232    0.02480 23.00000   0.497    0.624    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) shckC1 reps1
## shockCond1  0.340              
## reps1       0.431  0.430       
## shckCnd1:r1 0.000  0.000  0.000
# stress means by run type
dmerge %>% filter(group == 'stress') %>%
  group_by(shockCond) %>%
  summarise(dprime = mean(dprime)) 
## # A tibble: 2 x 2
##   shockCond  dprime
##      <fctr>   <dbl>
## 1      safe 1.49397
## 2    threat 1.46350
# effect of group just within safe?
summary(lmer(dprime ~ group * reps + 
               (1| subid), data=dmerge %>% filter(shockCond == 'safe')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: dprime ~ group * reps + (1 | subid)
##    Data: dmerge %>% filter(shockCond == "safe")
## 
## REML criterion at convergence: 174.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.05400 -0.44801  0.00997  0.37107  2.13855 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.55945  0.7480  
##  Residual             0.09165  0.3027  
## Number of obs: 94, groups:  subid, 47
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   1.68107    0.11351 45.00000  14.810  < 2e-16 ***
## group1        0.18710    0.11351 45.00000   1.648    0.106    
## reps1         0.22473    0.03123 45.00000   7.195 5.24e-09 ***
## group1:reps1 -0.00952    0.03123 45.00000  -0.305    0.762    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 reps1
## group1      0.021              
## reps1       0.000  0.000       
## group1:rps1 0.000  0.000  0.021

Criterion stats

summary(lmer(c ~ group * shockCond * reps + 
               (1 + shockCond + reps| subid), data=dmerge)) #not enough obs for interaction RE
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: c ~ group * shockCond * reps + (1 + shockCond + reps | subid)
##    Data: dmerge
## 
## REML criterion at convergence: 105.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.43344 -0.40465  0.00636  0.41143  1.84765 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr       
##  subid    (Intercept) 0.272795 0.5223              
##           shockCond1  0.021279 0.1459   -0.12      
##           reps1       0.005285 0.0727   -0.25 -0.14
##  Residual             0.013596 0.1166              
## Number of obs: 188, groups:  subid, 47
## 
## Fixed effects:
##                          Estimate Std. Error        df t value Pr(>|t|)
## (Intercept)             -0.341156   0.076675 45.000000  -4.449 5.61e-05
## group1                  -0.041642   0.076675 45.000000  -0.543    0.590
## shockCond1               0.002580   0.022920 45.000000   0.113    0.911
## reps1                   -0.103651   0.013596 45.000000  -7.624 1.22e-09
## group1:shockCond1        0.013755   0.022920 45.000000   0.600    0.551
## group1:reps1             0.007314   0.013596 45.000000   0.538    0.593
## shockCond1:reps1        -0.008712   0.008506 45.000000  -1.024    0.311
## group1:shockCond1:reps1 -0.002554   0.008506 45.000000  -0.300    0.765
##                            
## (Intercept)             ***
## group1                     
## shockCond1                 
## reps1                   ***
## group1:shockCond1          
## group1:reps1               
## shockCond1:reps1           
## group1:shockCond1:reps1    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1 reps1  gr1:C1 grp1:1 shC1:1
## group1       0.021                                          
## shockCond1  -0.114 -0.002                                   
## reps1       -0.192 -0.004 -0.099                            
## grp1:shckC1 -0.002 -0.114  0.021 -0.002                     
## group1:rps1 -0.004 -0.192 -0.002  0.021 -0.099              
## shckCnd1:r1  0.000  0.000  0.000  0.000  0.000  0.000       
## grp1:shC1:1  0.000  0.000  0.000  0.000  0.000  0.000  0.021

Does cortisol affect dprime?

d_cort = read.csv('/Volumes/group/awagner/sgagnon/AP/data/cortisol/cort_percentchange_testbaseline.csv')

dprime_cort = dmerge %>% left_join(d_cort)
## Joining, by = c("subid", "group")
str(dprime_cort)
## Classes 'tbl_df', 'tbl' and 'data.frame':    188 obs. of  18 variables:
##  $ subid     : Factor w/ 47 levels "ap100","ap101",..: 1 1 1 1 2 2 2 2 3 3 ...
##  $ group     : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##   ..- attr(*, "contrasts")= num [1:2, 1] 1 -1
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr  "control" "stress"
##   .. .. ..$ : NULL
##  $ shockCond : Factor w/ 2 levels "safe","threat": 1 2 1 2 1 2 1 2 1 2 ...
##   ..- attr(*, "contrasts")= num [1:2, 1] 1 -1
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr  "safe" "threat"
##   .. .. ..$ : NULL
##  $ reps      : Factor w/ 2 levels "2","4": 1 1 2 2 1 1 2 2 1 1 ...
##   ..- attr(*, "contrasts")= num [1:2, 1] -1 1
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr  "2" "4"
##   .. .. ..$ : NULL
##  $ hits      : num  29 32 31 35 28 32 39 34 40 36 ...
##  $ olds      : int  38 42 38 42 42 42 42 42 42 40 ...
##  $ fas       : num  8 8 8 8 1 1 1 1 33 28 ...
##  $ news      : int  37 42 37 42 42 42 42 42 42 42 ...
##  $ hitRate   : num  0.763 0.762 0.816 0.833 0.667 ...
##  $ faRate    : num  0.2162 0.1905 0.2162 0.1905 0.0238 ...
##  $ halfHit   : num  0.0132 0.0119 0.0132 0.0119 0.0119 ...
##  $ halfFA    : num  0.0135 0.0119 0.0135 0.0119 0.0119 ...
##  $ crRate    : num  0.784 0.81 0.784 0.81 0.976 ...
##  $ dprime    : num  1.5 1.59 1.68 1.84 2.41 ...
##  $ c         : num  0.0343 0.0818 -0.0572 -0.0456 0.775 ...
##  $ X         : int  0 0 0 0 1 1 1 1 2 2 ...
##  $ assay     : Factor w/ 2 levels "IBL","Salimetrics": 1 1 1 1 1 1 1 1 1 1 ...
##  $ log.ug.dL.: num  -7.36 -7.36 -7.36 -7.36 -17.43 ...
contrasts(dprime_cort$assay) = c(1,-1)
contrasts(dprime_cort$shockCond) = c(1,-1)
contrasts(dprime_cort$reps) = c(-1,1)
fit = lmer(dprime ~ scale(log.ug.dL.) * shockCond * reps + assay +
               (1 + shockCond + reps| subid), data=dprime_cort)
fit2 = lmer(dprime ~ poly(log.ug.dL.,2) * shockCond * reps + assay +
               (1 + shockCond + reps| subid), data=dprime_cort)
anova(fit, fit2)
## refitting model(s) with ML (instead of REML)
## Data: dprime_cort
## Models:
## object: dprime ~ scale(log.ug.dL.) * shockCond * reps + assay + (1 + 
## object:     shockCond + reps | subid)
## ..1: dprime ~ poly(log.ug.dL., 2) * shockCond * reps + assay + (1 + 
## ..1:     shockCond + reps | subid)
##        Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(>Chisq)
## object 16 284.59 336.37 -126.29   252.59                         
## ..1    20 289.49 354.22 -124.75   249.49 3.0955      4      0.542
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: dprime ~ scale(log.ug.dL.) * shockCond * reps + assay + (1 +  
##     shockCond + reps | subid)
##    Data: dprime_cort
## 
## REML criterion at convergence: 294.1
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.52112 -0.40713 -0.04724  0.44855  1.85670 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr       
##  subid    (Intercept) 0.57565  0.7587              
##           shockCond1  0.03472  0.1863   -0.11      
##           reps1       0.02168  0.1472    0.32 -0.06
##  Residual             0.05272  0.2296              
## Number of obs: 188, groups:  subid, 47
## 
## Fixed effects:
##                                     Estimate Std. Error        df t value
## (Intercept)                         1.661958   0.114915 44.410000  14.463
## scale(log.ug.dL.)                   0.150183   0.112264 44.130000   1.338
## shockCond1                         -0.005108   0.031924 45.000000  -0.160
## reps1                               0.207613   0.027235 45.000000   7.623
## assay1                              0.086461   0.111175 44.000000   0.778
## scale(log.ug.dL.):shockCond1        0.050873   0.032010 45.000000   1.589
## scale(log.ug.dL.):reps1            -0.009714   0.027307 45.000000  -0.356
## shockCond1:reps1                    0.017314   0.016746 45.000000   1.034
## scale(log.ug.dL.):shockCond1:reps1 -0.020646   0.016791 45.000000  -1.230
##                                    Pr(>|t|)    
## (Intercept)                         < 2e-16 ***
## scale(log.ug.dL.)                     0.188    
## shockCond1                            0.874    
## reps1                              1.23e-09 ***
## assay1                                0.441    
## scale(log.ug.dL.):shockCond1          0.119    
## scale(log.ug.dL.):reps1               0.724    
## shockCond1:reps1                      0.307    
## scale(log.ug.dL.):shockCond1:reps1    0.225    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) sc(..L.) shckC1 reps1  assay1 sc(..L.):C1 s(..L.):1
## scl(lg..L.) -0.006                                                    
## shockCond1  -0.089  0.000                                             
## reps1        0.242  0.000   -0.043                                    
## assay1      -0.226  0.025    0.000  0.000                             
## sc(..L.):C1  0.000 -0.091    0.000  0.000  0.000                      
## scl(..L.):1  0.000  0.248    0.000  0.000  0.000 -0.043               
## shckCnd1:r1  0.000  0.000    0.000  0.000  0.000  0.000       0.000   
## s(..L.):C1:  0.000  0.000    0.000  0.000  0.000  0.000       0.000   
##             shC1:1
## scl(lg..L.)       
## shockCond1        
## reps1             
## assay1            
## sc(..L.):C1       
## scl(..L.):1       
## shckCnd1:r1       
## s(..L.):C1:  0.000

Just to check, break down dprime also by indoor/outdoor associate

(doesn’t make as much sense here, since collapsing across associates in saying)

# get obj counts
obj_counts = dtest %>% group_by(subid, group, cond, reps, shockCond, obj_status) %>%
  summarise(count = n()) %>%
  rename(trial_type = obj_status) %>%
  ungroup()

# get counts by bin
coded_counts = dtest %>% 
  filter(acc %in% c('H', 'SM', 'FA')) %>%
  mutate(acc = ifelse(acc == 'FA', 'fa', 'hit')) %>%
  group_by(subid, group, cond, reps, shockCond, acc) %>%
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), shockCond, nesting(cond, reps, acc), 
           fill = list(count = 0))

# combine hits and olds
d_old = coded_counts %>% filter(acc == 'hit') %>%
  dplyr::select(-acc) %>%
  rename(hits = count) %>%
  right_join(obj_counts %>% 
              filter(trial_type == 'old') %>%
              dplyr::select(-trial_type) %>% 
              rename(olds = count))
## Joining, by = c("subid", "group", "shockCond", "cond", "reps")
# combine fas and news
d_new= coded_counts %>% filter(acc == 'fa') %>%
  dplyr::select(-acc) %>%
  rename(fas = count) %>%
  right_join(obj_counts %>% 
              filter(trial_type == 'new') %>%
              dplyr::select(-trial_type) %>% 
              rename(news = count)) %>%
  dplyr::select(-reps, -cond)
## Joining, by = c("subid", "group", "shockCond", "cond", "reps")
# compute hit/fa rates, and other
dmerge = d_old %>% left_join(d_new) %>%
  mutate(hitRate = hits/olds,
         faRate = fas/news,
         halfHit = 0.5/olds,
         halfFA = 0.5/news)
## Joining, by = c("subid", "group", "shockCond")
dmerge %>% group_by(subid, group, cond) %>%
  summarise(hitRate = mean(hitRate), faRate = mean(faRate)) %>%
  group_by(group, cond) %>%
  summarise_each(funs(mean)) %>%
  mutate(crRate = 1-faRate)
## Warning in mean.default(structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, :
## argument is not numeric or logical: returning NA

## Warning in mean.default(structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, :
## argument is not numeric or logical: returning NA
## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA

## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA
## Source: local data frame [4 x 6]
## Groups: group [2]
## 
## # A tibble: 4 x 6
##     group    cond subid   hitRate    faRate    crRate
##    <fctr>  <fctr> <lgl>     <dbl>     <dbl>     <dbl>
## 1 control  indoor    NA 0.8748706 0.3289757 0.6710243
## 2 control outdoor    NA 0.8843313 0.3289757 0.6710243
## 3  stress  indoor    NA 0.8043045 0.3618958 0.6381042
## 4  stress outdoor    NA 0.8148222 0.3618958 0.6381042
# replace 0 and 1s
dmerge = dmerge %>% mutate(faRate=ifelse(faRate==0, halfFA, faRate),
                  faRate=ifelse(faRate==1, 1-halfFA, faRate),
                  hitRate=ifelse(hitRate==0, halfHit, hitRate),
                  hitRate=ifelse(hitRate==1, 1-halfHit, hitRate))

# calc SDT measures
dmerge = dmerge %>% mutate(dprime = qnorm(hitRate) - qnorm(faRate),
                  c = -(qnorm(hitRate) + qnorm(faRate))/2) %>%
  mutate(reps = factor(reps), 
         cond = factor(cond))

dmerge
## # A tibble: 376 x 15
##     subid   group shockCond    cond   reps  hits  olds   fas  news
##    <fctr>  <fctr>    <fctr>  <fctr> <fctr> <dbl> <int> <dbl> <int>
##  1  ap100 control      safe  indoor      2    15    20     8    37
##  2  ap100 control    threat  indoor      2    16    21     8    42
##  3  ap100 control      safe  indoor      4    15    18     8    37
##  4  ap100 control    threat  indoor      4    16    21     8    42
##  5  ap100 control      safe outdoor      2    14    18     8    37
##  6  ap100 control    threat outdoor      2    16    21     8    42
##  7  ap100 control      safe outdoor      4    16    20     8    37
##  8  ap100 control    threat outdoor      4    19    21     8    42
##  9  ap101 control      safe  indoor      2    13    21     1    42
## 10  ap101 control    threat  indoor      2    15    21     1    42
## # ... with 366 more rows, and 6 more variables: hitRate <dbl>,
## #   faRate <dbl>, halfHit <dbl>, halfFA <dbl>, dprime <dbl>, c <dbl>
contrasts(dmerge$group) = c(1,-1)
contrasts(dmerge$shockCond) = c(1,-1)
contrasts(dmerge$reps) = c(-1,1)
contrasts(dmerge$cond) = c(-1,1)
summary(lmer(dprime ~ group * shockCond * reps + cond + 
               (1 + shockCond + reps + cond| subid), data=dmerge),
        control=lmerControl(optimizer="bobyqa",optCtrl=list(maxfun=5e5))) # failed to converge w/diff optimizers/increasing iters
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## dprime ~ group * shockCond * reps + cond + (1 + shockCond + reps +  
##     cond | subid)
##    Data: dmerge
## 
## REML criterion at convergence: 475.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.25446 -0.59296 -0.02828  0.52060  2.43531 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr             
##  subid    (Intercept) 0.544578 0.73796                   
##           shockCond1  0.037970 0.19486  -0.06            
##           reps1       0.013150 0.11467   0.28  0.03      
##           cond1       0.004991 0.07065  -0.14 -0.10 -0.55
##  Residual             0.081633 0.28571                   
## Number of obs: 376, groups:  subid, 47
## 
## Fixed effects:
##                           Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)              1.663e+00  1.087e-01  4.501e+01  15.307  < 2e-16
## group1                   1.905e-01  1.083e-01  4.500e+01   1.759   0.0853
## shockCond1              -1.074e-04  3.202e-02  4.500e+01  -0.003   0.9973
## reps1                    1.837e-01  2.230e-02  4.510e+01   8.240 1.52e-10
## cond1                    2.529e-02  1.798e-02  4.600e+01   1.406   0.1663
## group1:shockCond1       -1.305e-02  3.198e-02  4.500e+01  -0.408   0.6852
## group1:reps1            -2.178e-02  2.167e-02  4.500e+01  -1.005   0.3202
## shockCond1:reps1         1.889e-02  1.474e-02  1.860e+02   1.282   0.2014
## group1:shockCond1:reps1  9.647e-03  1.474e-02  1.860e+02   0.655   0.5135
##                            
## (Intercept)             ***
## group1                  .  
## shockCond1                 
## reps1                   ***
## cond1                      
## group1:shockCond1          
## group1:reps1               
## shockCond1:reps1           
## group1:shockCond1:reps1    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1 reps1  cond1  gr1:C1 grp1:1 shC1:1
## group1       0.021                                                 
## shockCond1  -0.049 -0.001                                          
## reps1        0.212  0.004  0.021                                   
## cond1       -0.081  0.000 -0.051 -0.236                            
## grp1:shckC1 -0.001 -0.054  0.021  0.000  0.000                     
## group1:rps1  0.004  0.199  0.000  0.021  0.000  0.009              
## shckCnd1:r1  0.000  0.000  0.000  0.000  0.000  0.000  0.000       
## grp1:shC1:1  0.000  0.000  0.000  0.000  0.000  0.000  0.000  0.021
# double check that no group:cond interaction
summary(lmer(dprime ~ group * shockCond * reps + cond + group:cond + 
               (1 + shockCond + reps + cond| subid), data=dmerge),
        control=lmerControl(optimizer="bobyqa",optCtrl=list(maxfun=5e5))) # failed to converge w/diff optimizers/increasing iters
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: dprime ~ group * shockCond * reps + cond + group:cond + (1 +  
##     shockCond + reps + cond | subid)
##    Data: dmerge
## 
## REML criterion at convergence: 481.7
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.23409 -0.58711 -0.02702  0.53125  2.41493 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr             
##  subid    (Intercept) 0.544649 0.73800                   
##           shockCond1  0.037973 0.19487  -0.06            
##           reps1       0.013175 0.11478   0.29  0.03      
##           cond1       0.005292 0.07274  -0.14 -0.10 -0.54
##  Residual             0.081633 0.28571                   
## Number of obs: 376, groups:  subid, 47
## 
## Fixed effects:
##                           Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)              1.663e+00  1.087e-01  4.500e+01  15.307  < 2e-16
## group1                   1.935e-01  1.087e-01  4.500e+01   1.780   0.0818
## shockCond1              -9.589e-05  3.202e-02  4.500e+01  -0.003   0.9976
## reps1                    1.838e-01  2.231e-02  4.500e+01   8.237 1.56e-10
## cond1                    2.516e-02  1.816e-02  4.500e+01   1.385   0.1727
## group1:shockCond1       -1.251e-02  3.202e-02  4.500e+01  -0.391   0.6979
## group1:reps1            -2.003e-02  2.231e-02  4.500e+01  -0.898   0.3739
## shockCond1:reps1         1.889e-02  1.474e-02  1.860e+02   1.282   0.2014
## group1:cond1            -5.981e-03  1.816e-02  4.500e+01  -0.329   0.7434
## group1:shockCond1:reps1  9.647e-03  1.474e-02  1.860e+02   0.655   0.5135
##                            
## (Intercept)             ***
## group1                  .  
## shockCond1                 
## reps1                   ***
## cond1                      
## group1:shockCond1          
## group1:reps1               
## shockCond1:reps1           
## group1:cond1               
## group1:shockCond1:reps1    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1 reps1  cond1  gr1:C1 grp1:r1 shC1:1
## group1       0.021                                                  
## shockCond1  -0.049 -0.001                                           
## reps1        0.212  0.005  0.021                                    
## cond1       -0.082 -0.002 -0.051 -0.238                             
## grp1:shckC1 -0.001 -0.049  0.021  0.000 -0.001                      
## group1:rps1  0.005  0.212  0.000  0.021 -0.005  0.021               
## shckCnd1:r1  0.000  0.000  0.000  0.000  0.000  0.000  0.000        
## group1:cnd1 -0.002 -0.082 -0.001 -0.005  0.021 -0.051 -0.238   0.000
## grp1:shC1:1  0.000  0.000  0.000  0.000  0.000  0.000  0.000   0.021
##             grp1:c1
## group1             
## shockCond1         
## reps1              
## cond1              
## grp1:shckC1        
## group1:rps1        
## shckCnd1:r1        
## group1:cnd1        
## grp1:shC1:1  0.000

1b) HC associative dprime

Calculate HC associative dprimes/criterion

# get obj counts
obj_counts = dtest %>% filter(cond %in% c('indoor',
                                          'outdoor')) %>%
  group_by(subid, group, reps, 
           cond, shockCond, obj_status) %>%
  summarise(count = n()) %>%
  rename(trial_type = obj_status) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, nesting(reps, cond, trial_type), 
           fill = list(count = 0))
obj_counts
## # A tibble: 376 x 7
##     subid   group shockCond  reps    cond trial_type count
##    <fctr>  <fctr>    <fctr> <int>  <fctr>      <chr> <dbl>
##  1  ap100 control      safe     2  indoor        old    20
##  2  ap100 control      safe     2 outdoor        old    18
##  3  ap100 control      safe     4  indoor        old    18
##  4  ap100 control      safe     4 outdoor        old    20
##  5  ap100 control    threat     2  indoor        old    21
##  6  ap100 control    threat     2 outdoor        old    21
##  7  ap100 control    threat     4  indoor        old    21
##  8  ap100 control    threat     4 outdoor        old    21
##  9  ap101 control      safe     2  indoor        old    21
## 10  ap101 control      safe     2 outdoor        old    21
## # ... with 366 more rows
# write.csv(obj_counts, '~/Desktop/obj_counts.csv')

# get counts for hi conf assoc hits and misses
coded_counts = dtest %>% 
  filter(acc %in% c('H', 'SM'),
         conf == 'Hi') %>%
  group_by(subid, group, reps, shockCond, resp, cond, acc) %>%
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), shockCond, nesting(reps, acc, cond, resp), 
           fill = list(count = 0))
coded_counts
## # A tibble: 752 x 8
##     subid   group shockCond  reps    acc    cond    resp count
##    <fctr>  <fctr>    <fctr> <int> <fctr>  <fctr>  <fctr> <dbl>
##  1  ap100 control      safe     2      H  indoor  indoor    10
##  2  ap100 control      safe     2      H outdoor outdoor    10
##  3  ap100 control      safe     2     SM  indoor outdoor     0
##  4  ap100 control      safe     2     SM outdoor  indoor     1
##  5  ap100 control      safe     4      H  indoor  indoor    12
##  6  ap100 control      safe     4      H outdoor outdoor    14
##  7  ap100 control      safe     4     SM  indoor outdoor     3
##  8  ap100 control      safe     4     SM outdoor  indoor     1
##  9  ap100 control    threat     2      H  indoor  indoor    10
## 10  ap100 control    threat     2      H outdoor outdoor    10
## # ... with 742 more rows
# write.csv(coded_counts, '~/Desktop/coded_counts.csv')

# combine hits and olds (on condition)
hit_rates = coded_counts %>%
  filter(acc == 'H') %>%
  rename(resp_rate = count) %>%
  right_join(obj_counts %>% 
              filter(trial_type == 'old') %>%
              dplyr::select(-trial_type) %>% 
              rename(olds = count)) %>%
     mutate(H = resp_rate/olds, half_rate = 0.5/olds,
         H=ifelse(H==0, half_rate, H),
         H=ifelse(H==1, 1-half_rate, H)) %>%
  dplyr::select(-resp_rate, -olds, -half_rate, -cond, -acc)
## Joining, by = c("subid", "group", "shockCond", "reps", "cond")
hit_rates
## # A tibble: 376 x 6
##     subid   group shockCond  reps    resp         H
##    <fctr>  <fctr>    <fctr> <int>  <fctr>     <dbl>
##  1  ap100 control      safe     2  indoor 0.5000000
##  2  ap100 control      safe     2 outdoor 0.5555556
##  3  ap100 control      safe     4  indoor 0.6666667
##  4  ap100 control      safe     4 outdoor 0.7000000
##  5  ap100 control    threat     2  indoor 0.4761905
##  6  ap100 control    threat     2 outdoor 0.4761905
##  7  ap100 control    threat     4  indoor 0.4761905
##  8  ap100 control    threat     4 outdoor 0.6190476
##  9  ap101 control      safe     2  indoor 0.4285714
## 10  ap101 control      safe     2 outdoor 0.4285714
## # ... with 366 more rows
# combine SHs (response) and olds (condition)
sm_rates = coded_counts %>%
  filter(acc == 'SM') %>%
  rename(resp_rate = count) %>%
  right_join(obj_counts %>% 
              filter(trial_type == 'old') %>%
              dplyr::select(-trial_type) %>% 
              rename(olds = count)) %>%
     mutate(SM = resp_rate/olds, half_rate = 0.5/olds,
         SM=ifelse(SM==0, half_rate, SM),
         SM=ifelse(SM==1, 1-half_rate, SM)) %>%
  dplyr::select(-resp_rate, -olds, -half_rate, -cond, -acc)
## Joining, by = c("subid", "group", "shockCond", "reps", "cond")
sm_rates
## # A tibble: 376 x 6
##     subid   group shockCond  reps    resp         SM
##    <fctr>  <fctr>    <fctr> <int>  <fctr>      <dbl>
##  1  ap100 control      safe     2 outdoor 0.02500000
##  2  ap100 control      safe     2  indoor 0.05555556
##  3  ap100 control      safe     4 outdoor 0.16666667
##  4  ap100 control      safe     4  indoor 0.05000000
##  5  ap100 control    threat     2 outdoor 0.09523810
##  6  ap100 control    threat     2  indoor 0.04761905
##  7  ap100 control    threat     4 outdoor 0.09523810
##  8  ap100 control    threat     4  indoor 0.14285714
##  9  ap101 control      safe     2 outdoor 0.09523810
## 10  ap101 control      safe     2  indoor 0.04761905
## # ... with 366 more rows
# join on response (e.g., "indoor" hit to indoor - fa "indoor"" to outdoor)
dmerge = hit_rates %>% left_join(sm_rates)
## Joining, by = c("subid", "group", "shockCond", "reps", "resp")
dmerge
## # A tibble: 376 x 7
##     subid   group shockCond  reps    resp         H         SM
##    <fctr>  <fctr>    <fctr> <int>  <fctr>     <dbl>      <dbl>
##  1  ap100 control      safe     2  indoor 0.5000000 0.05555556
##  2  ap100 control      safe     2 outdoor 0.5555556 0.02500000
##  3  ap100 control      safe     4  indoor 0.6666667 0.05000000
##  4  ap100 control      safe     4 outdoor 0.7000000 0.16666667
##  5  ap100 control    threat     2  indoor 0.4761905 0.04761905
##  6  ap100 control    threat     2 outdoor 0.4761905 0.09523810
##  7  ap100 control    threat     4  indoor 0.4761905 0.14285714
##  8  ap100 control    threat     4 outdoor 0.6190476 0.09523810
##  9  ap101 control      safe     2  indoor 0.4285714 0.04761905
## 10  ap101 control      safe     2 outdoor 0.4285714 0.09523810
## # ... with 366 more rows
# calc SDT measures
dmerge = dmerge %>% mutate(dprime = qnorm(H) - qnorm(SM),
                           c = -(qnorm(H) + qnorm(SM))/2) %>%
  mutate(reps = factor(reps),
         resp = factor(resp))
dmerge
## # A tibble: 376 x 9
##     subid   group shockCond   reps    resp         H         SM   dprime
##    <fctr>  <fctr>    <fctr> <fctr>  <fctr>     <dbl>      <dbl>    <dbl>
##  1  ap100 control      safe      2  indoor 0.5000000 0.05555556 1.593219
##  2  ap100 control      safe      2 outdoor 0.5555556 0.02500000 2.099674
##  3  ap100 control      safe      4  indoor 0.6666667 0.05000000 2.075581
##  4  ap100 control      safe      4 outdoor 0.7000000 0.16666667 1.491822
##  5  ap100 control    threat      2  indoor 0.4761905 0.04761905 1.608674
##  6  ap100 control    threat      2 outdoor 0.4761905 0.09523810 1.249455
##  7  ap100 control    threat      4  indoor 0.4761905 0.14285714 1.007853
##  8  ap100 control    threat      4 outdoor 0.6190476 0.09523810 1.612152
##  9  ap101 control      safe      2  indoor 0.4285714 0.04761905 1.488379
## 10  ap101 control      safe      2 outdoor 0.4285714 0.09523810 1.129159
## # ... with 366 more rows, and 1 more variables: c <dbl>
dmerge %>% group_by(subid, group) %>%
  summarise(hitRate=mean(H), 
            smRate=mean(SM), 
            dprime=mean(dprime),
            c = mean(c)) %>%
  group_by(group) %>%
  summarise_each(funs(mean))
## Warning in mean.default(structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, :
## argument is not numeric or logical: returning NA
## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA
## # A tibble: 2 x 6
##     group subid   hitRate     smRate    dprime        c
##    <fctr> <lgl>     <dbl>      <dbl>     <dbl>    <dbl>
## 1 control    NA 0.4893292 0.10009728 1.3663338 0.731530
## 2  stress    NA 0.3043761 0.09622391 0.8003808 1.038548
assoc_d = dmerge

assoc_d
## # A tibble: 376 x 9
##     subid   group shockCond   reps    resp         H         SM   dprime
##    <fctr>  <fctr>    <fctr> <fctr>  <fctr>     <dbl>      <dbl>    <dbl>
##  1  ap100 control      safe      2  indoor 0.5000000 0.05555556 1.593219
##  2  ap100 control      safe      2 outdoor 0.5555556 0.02500000 2.099674
##  3  ap100 control      safe      4  indoor 0.6666667 0.05000000 2.075581
##  4  ap100 control      safe      4 outdoor 0.7000000 0.16666667 1.491822
##  5  ap100 control    threat      2  indoor 0.4761905 0.04761905 1.608674
##  6  ap100 control    threat      2 outdoor 0.4761905 0.09523810 1.249455
##  7  ap100 control    threat      4  indoor 0.4761905 0.14285714 1.007853
##  8  ap100 control    threat      4 outdoor 0.6190476 0.09523810 1.612152
##  9  ap101 control      safe      2  indoor 0.4285714 0.04761905 1.488379
## 10  ap101 control      safe      2 outdoor 0.4285714 0.09523810 1.129159
## # ... with 366 more rows, and 1 more variables: c <dbl>

HC assoc dprime stats

contrasts(dmerge$group) = c(1,-1)
contrasts(dmerge$shockCond) = c(1,-1)
contrasts(dmerge$reps) = c(-1,1)
contrasts(dmerge$resp) = c(-1,1); contrasts(dmerge$resp)
##         [,1]
## indoor    -1
## outdoor    1
# hist(dmerge$dprime)
# dmerge

dmerge %>% group_by(subid, group) %>% summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    23
## 2  stress    24
# include group interactions by resp, shockcond, reps
summary(lmer(dprime ~ group * (shockCond * reps + resp) + 
               (1 + reps + shockCond + resp| subid), data=dmerge,
             control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## dprime ~ group * (shockCond * reps + resp) + (1 + reps + shockCond +  
##     resp | subid)
##    Data: dmerge
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 618.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.89600 -0.65280 -0.09113  0.61185  2.51073 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr          
##  subid    (Intercept) 0.4802490 0.69300                
##           reps1       0.0140203 0.11841  0.58          
##           shockCond1  0.0090010 0.09487  0.33 0.32     
##           resp1       0.0006083 0.02466  0.26 0.67 0.55
##  Residual             0.1669692 0.40862                
## Number of obs: 376, groups:  subid, 47
## 
## Fixed effects:
##                           Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)               1.083357   0.103281  45.000000  10.489 1.14e-13
## group1                    0.282976   0.103281  45.000000   2.740  0.00878
## shockCond1               -0.017786   0.025216  45.000000  -0.705  0.48424
## reps1                     0.210234   0.027253  45.000000   7.714 9.01e-10
## resp1                     0.039831   0.021383  45.000000   1.863  0.06903
## shockCond1:reps1          0.050742   0.021078 186.000000   2.407  0.01704
## group1:shockCond1         0.024053   0.025216  45.000000   0.954  0.34525
## group1:reps1              0.058947   0.027253  45.000000   2.163  0.03589
## group1:resp1             -0.020491   0.021383  45.000000  -0.958  0.34303
## group1:shockCond1:reps1   0.008746   0.021078 186.000000   0.415  0.67867
##                            
## (Intercept)             ***
## group1                  ** 
## shockCond1                 
## reps1                   ***
## resp1                   .  
## shockCond1:reps1        *  
## group1:shockCond1          
## group1:reps1            *  
## group1:resp1               
## group1:shockCond1:reps1    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1 reps1 resp1 shC1:1 gr1:C1 grp1:rp1
## group1      0.021                                                  
## shockCond1  0.179  0.004                                           
## reps1       0.358  0.008  0.111                                    
## resp1       0.044  0.001  0.051  0.071                             
## shckCnd1:r1 0.000  0.000  0.000  0.000 0.000                       
## grp1:shckC1 0.004  0.179  0.021  0.002 0.001 0.000                 
## group1:rps1 0.008  0.358  0.002  0.021 0.002 0.000  0.111          
## group1:rsp1 0.001  0.044  0.001  0.002 0.021 0.000  0.051  0.071   
## grp1:shC1:1 0.000  0.000  0.000  0.000 0.000 0.021  0.000  0.000   
##             grp1:rs1
## group1              
## shockCond1          
## reps1               
## resp1               
## shckCnd1:r1         
## grp1:shckC1         
## group1:rps1         
## group1:rsp1         
## grp1:shC1:1 0.000
# does effect hold looking at safe block?
summary(lmer(dprime ~ group * (reps + resp) + 
               (1 + reps + resp| subid), data=dmerge %>% filter(shockCond == 'safe'),
             control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: dprime ~ group * (reps + resp) + (1 + reps + resp | subid)
##    Data: dmerge %>% filter(shockCond == "safe")
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 343.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.51099 -0.53218 -0.00686  0.52236  2.17675 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr       
##  subid    (Intercept) 0.546522 0.73927             
##           reps1       0.055751 0.23612   0.30      
##           resp1       0.007481 0.08649   0.15 -0.05
##  Residual             0.112738 0.33576             
## Number of obs: 188, groups:  subid, 47
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   1.06557    0.11060 45.00000   9.634 1.65e-12 ***
## group1        0.30703    0.11060 45.00000   2.776  0.00799 ** 
## reps1         0.26098    0.04227 45.00000   6.174 1.72e-07 ***
## resp1         0.02350    0.02755 45.00000   0.853  0.39827    
## group1:reps1  0.06769    0.04227 45.00000   1.601  0.11627    
## group1:resp1 -0.03397    0.02755 45.00000  -1.233  0.22407    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 reps1  resp1  grp1:rp1
## group1       0.021                              
## reps1        0.236  0.005                       
## resp1        0.066  0.001 -0.017                
## group1:rps1  0.005  0.236  0.021  0.000         
## group1:rsp1  0.001  0.066  0.000  0.021 -0.017
# is effect of group diff for 2 vs 4 reps?
summary(lmer(dprime ~ group * (shockCond + resp) + 
               (1 + shockCond + resp| subid), data=dmerge %>% filter(reps == 2),
             control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: dprime ~ group * (shockCond + resp) + (1 + shockCond + resp |  
##     subid)
##    Data: dmerge %>% filter(reps == 2)
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 320.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.96727 -0.49930 -0.01663  0.45363  2.07175 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr       
##  subid    (Intercept) 0.41927  0.6475              
##           shockCond1  0.04727  0.2174    0.16      
##           resp1       0.02063  0.1436   -0.09 -0.33
##  Residual             0.08871  0.2978              
## Number of obs: 188, groups:  subid, 47
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)        0.87312    0.09694 45.00000   9.007 1.24e-11 ***
## group1             0.22403    0.09694 45.00000   2.311   0.0255 *  
## shockCond1        -0.06853    0.03845 45.00000  -1.782   0.0814 .  
## resp1              0.04880    0.03019 45.00000   1.617   0.1129    
## group1:shockCond1  0.01531    0.03845 45.00000   0.398   0.6924    
## group1:resp1      -0.01551    0.03019 45.00000  -0.514   0.6100    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1 resp1  gr1:C1
## group1       0.021                            
## shockCond1   0.126  0.003                     
## resp1       -0.058 -0.001 -0.188              
## grp1:shckC1  0.003  0.126  0.021 -0.004       
## group1:rsp1 -0.001 -0.058 -0.004  0.021 -0.188
summary(lmer(dprime ~ group * (shockCond + resp) + 
               (1 + shockCond + resp| subid), data=dmerge %>% filter(reps == 4),
             control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: dprime ~ group * (shockCond + resp) + (1 + shockCond + resp |  
##     subid)
##    Data: dmerge %>% filter(reps == 4)
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 344.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.51451 -0.52416 -0.03364  0.54392  1.77758 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr     
##  subid    (Intercept) 0.60208  0.7759            
##           shockCond1  0.04000  0.2000   0.20     
##           resp1       0.01285  0.1134   0.20 0.50
##  Residual             0.11398  0.3376            
## Number of obs: 188, groups:  subid, 47
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)        1.29359    0.11586 45.00000  11.166 1.47e-14 ***
## group1             0.34192    0.11586 45.00000   2.951  0.00501 ** 
## shockCond1         0.03296    0.03818 45.00000   0.863  0.39267    
## resp1              0.03086    0.02967 45.00000   1.040  0.30380    
## group1:shockCond1  0.03280    0.03818 45.00000   0.859  0.39493    
## group1:resp1      -0.02548    0.02967 45.00000  -0.859  0.39504    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1 resp1 gr1:C1
## group1      0.021                            
## shockCond1  0.152  0.003                     
## resp1       0.108  0.002  0.214              
## grp1:shckC1 0.003  0.152  0.021  0.005       
## group1:rsp1 0.002  0.108  0.005  0.021 0.214
# check out group x reps interaction + shockCond just within stress group
summary(lmer(dprime ~ shockCond * reps + resp + 
               (1 + reps * shockCond + resp| subid), 
             data=dmerge %>% filter(group == 'stress'),
             control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## dprime ~ shockCond * reps + resp + (1 + reps * shockCond + resp |  
##     subid)
##    Data: dmerge %>% filter(group == "stress")
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 304.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.38556 -0.62450 -0.08574  0.47480  2.20730 
## 
## Random effects:
##  Groups   Name             Variance Std.Dev. Corr                   
##  subid    (Intercept)      0.357979 0.59831                         
##           reps1            0.005456 0.07386   0.86                  
##           shockCond1       0.013854 0.11770   0.37  0.21            
##           resp1            0.003892 0.06239  -0.41 -0.65  0.59      
##           reps1:shockCond1 0.014490 0.12037   0.43  0.42  0.56  0.21
##  Residual                  0.157827 0.39727                         
## Number of obs: 192, groups:  subid, 24
## 
## Fixed effects:
##                  Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)       0.80038    0.12545 23.00000   6.380 1.64e-06 ***
## shockCond1       -0.04184    0.03741 23.47000  -1.118   0.2747    
## reps1             0.15129    0.03239 30.53000   4.670 5.69e-05 ***
## resp1             0.06032    0.03137 36.28000   1.923   0.0624 .  
## shockCond1:reps1  0.04200    0.03776 23.03000   1.112   0.2775    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) shckC1 reps1  resp1 
## shockCond1   0.230                     
## reps1        0.391  0.063              
## resp1       -0.161  0.155 -0.122       
## shckCnd1:r1  0.274  0.234  0.126  0.054
# simple effects to double check:
# control
contrasts(dmerge$group) = c(0,1); contrasts(dmerge$group)
##         [,1]
## control    0
## stress     1
summary(lmer(dprime ~ group * (shockCond * reps + resp) + 
               (1 + reps + shockCond + resp| subid), data=dmerge,
             control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## dprime ~ group * (shockCond * reps + resp) + (1 + reps + shockCond +  
##     resp | subid)
##    Data: dmerge
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 611.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.89600 -0.65280 -0.09113  0.61185  2.51073 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr          
##  subid    (Intercept) 0.4802498 0.69300                
##           reps1       0.0140203 0.11841  0.58          
##           shockCond1  0.0090010 0.09487  0.33 0.32     
##           resp1       0.0006083 0.02466  0.26 0.67 0.55
##  Residual             0.1669692 0.40862                
## Number of obs: 376, groups:  subid, 47
## 
## Fixed effects:
##                           Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)               1.366334   0.147607  45.000000   9.257 5.52e-12
## group1                   -0.565953   0.206562  45.000000  -2.740  0.00878
## shockCond1                0.006267   0.036039  45.000000   0.174  0.86273
## reps1                     0.269181   0.038949  45.000000   6.911 1.38e-08
## resp1                     0.019340   0.030560  45.000000   0.633  0.53003
## shockCond1:reps1          0.059488   0.030124 186.000000   1.975  0.04977
## group1:shockCond1        -0.048105   0.050433  45.000000  -0.954  0.34525
## group1:reps1             -0.117895   0.054505  45.000000  -2.163  0.03589
## group1:resp1              0.040982   0.042765  45.000000   0.958  0.34303
## group1:shockCond1:reps1  -0.017492   0.042155 186.000000  -0.415  0.67867
##                            
## (Intercept)             ***
## group1                  ** 
## shockCond1                 
## reps1                   ***
## resp1                      
## shockCond1:reps1        *  
## group1:shockCond1          
## group1:reps1            *  
## group1:resp1               
## group1:shockCond1:reps1    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1 reps1  resp1  shC1:1 gr1:C1 grp1:rp1
## group1      -0.715                                                   
## shockCond1   0.179 -0.128                                            
## reps1        0.358 -0.256  0.111                                     
## resp1        0.044 -0.031  0.051  0.071                              
## shckCnd1:r1  0.000  0.000  0.000  0.000  0.000                       
## grp1:shckC1 -0.128  0.179 -0.715 -0.079 -0.036  0.000                
## group1:rps1 -0.256  0.358 -0.079 -0.715 -0.051  0.000  0.111         
## group1:rsp1 -0.031  0.044 -0.036 -0.051 -0.715  0.000  0.051  0.071  
## grp1:shC1:1  0.000  0.000  0.000  0.000  0.000 -0.715  0.000  0.000  
##             grp1:rs1
## group1              
## shockCond1          
## reps1               
## resp1               
## shckCnd1:r1         
## grp1:shckC1         
## group1:rps1         
## group1:rsp1         
## grp1:shC1:1  0.000
# stress
contrasts(dmerge$group) = c(1,0); contrasts(dmerge$group)
##         [,1]
## control    1
## stress     0
summary(lmer(dprime ~ group * (shockCond * reps + resp) + 
               (1 + reps + shockCond + resp| subid), data=dmerge,
             control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## dprime ~ group * (shockCond * reps + resp) + (1 + reps + shockCond +  
##     resp | subid)
##    Data: dmerge
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 611.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.89600 -0.65280 -0.09113  0.61185  2.51073 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr          
##  subid    (Intercept) 0.4802491 0.69300                
##           reps1       0.0140203 0.11841  0.58          
##           shockCond1  0.0090010 0.09487  0.33 0.32     
##           resp1       0.0006083 0.02466  0.26 0.67 0.55
##  Residual             0.1669692 0.40862                
## Number of obs: 376, groups:  subid, 47
## 
## Fixed effects:
##                          Estimate Std. Error        df t value Pr(>|t|)
## (Intercept)               0.80038    0.14450  45.00000   5.539  1.5e-06
## group1                    0.56595    0.20656  45.00000   2.740 0.008780
## shockCond1               -0.04184    0.03528  45.00000  -1.186 0.241887
## reps1                     0.15129    0.03813  45.00000   3.968 0.000258
## resp1                     0.06032    0.02992  45.00000   2.016 0.049754
## shockCond1:reps1          0.04200    0.02949 186.00000   1.424 0.156088
## group1:shockCond1         0.04811    0.05043  45.00000   0.954 0.345255
## group1:reps1              0.11789    0.05451  45.00000   2.163 0.035892
## group1:resp1             -0.04098    0.04277  45.00000  -0.958 0.343029
## group1:shockCond1:reps1   0.01749    0.04216 186.00000   0.415 0.678671
##                            
## (Intercept)             ***
## group1                  ** 
## shockCond1                 
## reps1                   ***
## resp1                   *  
## shockCond1:reps1           
## group1:shockCond1          
## group1:reps1            *  
## group1:resp1               
## group1:shockCond1:reps1    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1 reps1  resp1  shC1:1 gr1:C1 grp1:rp1
## group1      -0.700                                                   
## shockCond1   0.179 -0.125                                            
## reps1        0.358 -0.250  0.111                                     
## resp1        0.044 -0.030  0.051  0.071                              
## shckCnd1:r1  0.000  0.000  0.000  0.000  0.000                       
## grp1:shckC1 -0.125  0.179 -0.700 -0.077 -0.036  0.000                
## group1:rps1 -0.250  0.358 -0.077 -0.700 -0.050  0.000  0.111         
## group1:rsp1 -0.030  0.044 -0.036 -0.050 -0.700  0.000  0.051  0.071  
## grp1:shC1:1  0.000  0.000  0.000  0.000  0.000 -0.700  0.000  0.000  
##             grp1:rs1
## group1              
## shockCond1          
## reps1               
## resp1               
## shckCnd1:r1         
## grp1:shckC1         
## group1:rps1         
## group1:rsp1         
## grp1:shC1:1  0.000
contrasts(dmerge$group) = c(1,-1)


# stress means by run type
dmerge %>% filter(group == 'stress') %>%
  group_by(subid, shockCond) %>%
  summarise(dprime = mean(dprime)) %>%
  group_by(shockCond) %>%
  summarise(dprime = mean(dprime)) 
## # A tibble: 2 x 2
##   shockCond    dprime
##      <fctr>     <dbl>
## 1      safe 0.7585424
## 2    threat 0.8422192

What about high confidence FA rates?

# Calculate high confidence FA rate
dat_fa = dtest %>%
  filter(cond %in% c('foil'),
         acc == 'FA') %>%
  group_by(subid, group, shockCond, conf) %>%
  summarise(count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, conf, 
           fill = list(count = 0)) %>%
  filter(conf == 'Hi')
head(dat_fa)
## # A tibble: 6 x 5
##    subid   group shockCond   conf count
##   <fctr>  <fctr>    <fctr> <fctr> <dbl>
## 1  ap100 control      safe     Hi     1
## 2  ap100 control    threat     Hi     2
## 3  ap101 control      safe     Hi     1
## 4  ap101 control    threat     Hi     0
## 5  ap102 control      safe     Hi     4
## 6  ap102 control    threat     Hi     4
new_counts = dtest %>%
  filter(cond %in% c('foil')) %>%
  mutate(cond = factor(cond),
         acc = factor(acc)) %>%
  group_by(subid, group, shockCond) %>%
  summarise(count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, fill = list(count = 0))
min(new_counts$count)
## [1] 28
head(new_counts)
## # A tibble: 6 x 4
##    subid   group shockCond count
##   <fctr>  <fctr>    <fctr> <dbl>
## 1  ap100 control      safe    37
## 2  ap100 control    threat    42
## 3  ap101 control      safe    42
## 4  ap101 control    threat    42
## 5  ap102 control      safe    42
## 6  ap102 control    threat    42
dat_fa = dat_fa %>% 
  left_join(new_counts %>% rename(new_count = count)) %>%
  mutate(fa_rate = count/new_count)
## Joining, by = c("subid", "group", "shockCond")
head(dat_fa)
## # A tibble: 6 x 7
##    subid   group shockCond   conf count new_count    fa_rate
##   <fctr>  <fctr>    <fctr> <fctr> <dbl>     <dbl>      <dbl>
## 1  ap100 control      safe     Hi     1        37 0.02702703
## 2  ap100 control    threat     Hi     2        42 0.04761905
## 3  ap101 control      safe     Hi     1        42 0.02380952
## 4  ap101 control    threat     Hi     0        42 0.00000000
## 5  ap102 control      safe     Hi     4        42 0.09523810
## 6  ap102 control    threat     Hi     4        42 0.09523810
dat_fa %>% group_by(subid, group, shockCond) %>% 
  summarise(fa_rate = mean(fa_rate)) %>%
  group_by(group, shockCond) %>% 
  summarise(mean_fa = mean(fa_rate), se=std.error(fa_rate), n())
## Source: local data frame [4 x 5]
## Groups: group [?]
## 
## # A tibble: 4 x 5
##     group shockCond    mean_fa         se `n()`
##    <fctr>    <fctr>      <dbl>      <dbl> <int>
## 1 control      safe 0.06121650 0.01684408    23
## 2 control    threat 0.06366460 0.02103131    23
## 3  stress      safe 0.04960317 0.01410897    24
## 4  stress    threat 0.05497642 0.01331615    24
dat_fa %>% group_by(subid, group) %>% 
  summarise(fa_rate = mean(fa_rate)) %>%
  group_by(group) %>%
  summarise(mean_fa = mean(fa_rate), se=std.error(fa_rate), n())
## # A tibble: 2 x 4
##     group    mean_fa         se `n()`
##    <fctr>      <dbl>      <dbl> <int>
## 1 control 0.06244055 0.01779309    23
## 2  stress 0.05228980 0.01305370    24
hist(dat_fa$fa_rate)

hist(logit(dat_fa$fa_rate))

dat_fa = dat_fa %>% mutate(fa_rate_log = car::logit(fa_rate))
## Warning in car::logit(c(0.027027027027027, 0.0476190476190476,
## 0.0238095238095238, : proportions remapped to (0.025, 0.975)
contrasts(dat_fa$group) = c(1,-1); contrasts(dat_fa$group)
##         [,1]
## control    1
## stress    -1
contrasts(dat_fa$shockCond) = c(1,-1); contrasts(dat_fa$shockCond)
##        [,1]
## safe      1
## threat   -1
summary(lmer(fa_rate_log ~  group*shockCond + 
               (1 | subid), data=dat_fa,
             control=lmerControl(optimizer="bobyqa",optCtrl=list(maxfun=5e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: fa_rate_log ~ group * shockCond + (1 | subid)
##    Data: dat_fa
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 5e+05))
## 
## REML criterion at convergence: 219.7
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.88373 -0.54589  0.03345  0.46221  1.95393 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.4569   0.6760  
##  Residual             0.2579   0.5079  
## Number of obs: 94, groups:  subid, 47
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)       -2.75856    0.11168 45.00000 -24.701   <2e-16 ***
## group1             0.01933    0.11168 45.00000   0.173    0.863    
## shockCond1        -0.02575    0.05240 45.00000  -0.491    0.625    
## group1:shockCond1  0.05654    0.05240 45.00000   1.079    0.286    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1
## group1      0.021               
## shockCond1  0.000  0.000        
## grp1:shckC1 0.000  0.000  0.021

All assoc FA rates:

# Calculate high confidence FA rate
dat_fa = dtest %>%
  filter(cond %in% c('foil'),
         acc == 'FA') %>%
  group_by(subid, group, shockCond, conf) %>%
  summarise(count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, conf, 
           fill = list(count = 0))
head(dat_fa)
## # A tibble: 6 x 5
##    subid   group shockCond   conf count
##   <fctr>  <fctr>    <fctr> <fctr> <dbl>
## 1  ap100 control      safe     Hi     1
## 2  ap100 control      safe     Lo     7
## 3  ap100 control      safe      N     0
## 4  ap100 control    threat     Hi     2
## 5  ap100 control    threat     Lo     6
## 6  ap100 control    threat      N     0
new_counts = dtest %>%
  filter(cond %in% c('foil')) %>%
  mutate(cond = factor(cond),
         acc = factor(acc)) %>%
  group_by(subid, group, shockCond) %>%
  summarise(count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, 
           fill = list(count = 0))

dat_fa = dat_fa %>% 
  left_join(new_counts %>% rename(new_count = count)) %>%
  mutate(fa_rate = count/new_count)
## Joining, by = c("subid", "group", "shockCond")
dat_fa %>% group_by(subid, group, conf) %>% 
  summarise(fa_rate = mean(fa_rate)) %>%
  group_by(group, conf) %>%
  summarise(mean_fa = mean(fa_rate), se=std.error(fa_rate), n())
## Source: local data frame [6 x 5]
## Groups: group [?]
## 
## # A tibble: 6 x 5
##     group   conf    mean_fa         se `n()`
##    <fctr> <fctr>      <dbl>      <dbl> <int>
## 1 control     Hi 0.06244055 0.01779309    23
## 2 control     Lo 0.26653517 0.04050742    23
## 3 control      N 0.00000000 0.00000000    23
## 4  stress     Hi 0.05228980 0.01305370    24
## 5  stress     Lo 0.30960598 0.04339815    24
## 6  stress      N 0.00000000 0.00000000    24
dat_fa %>% group_by(subid, group, shockCond, conf) %>% 
  summarise(fa_rate = mean(fa_rate)) %>%
  group_by(group, conf, shockCond) %>%
  summarise(mean_fa = mean(fa_rate), se=std.error(fa_rate), n())
## Source: local data frame [12 x 6]
## Groups: group, conf [?]
## 
## # A tibble: 12 x 6
##      group   conf shockCond    mean_fa         se `n()`
##     <fctr> <fctr>    <fctr>      <dbl>      <dbl> <int>
##  1 control     Hi      safe 0.06121650 0.01684408    23
##  2 control     Hi    threat 0.06366460 0.02103131    23
##  3 control     Lo      safe 0.26909518 0.04101087    23
##  4 control     Lo    threat 0.26397516 0.04223021    23
##  5 control      N      safe 0.00000000 0.00000000    23
##  6 control      N    threat 0.00000000 0.00000000    23
##  7  stress     Hi      safe 0.04960317 0.01410897    24
##  8  stress     Hi    threat 0.05497642 0.01331615    24
##  9  stress     Lo      safe 0.31646825 0.04805868    24
## 10  stress     Lo    threat 0.30274370 0.04141771    24
## 11  stress      N      safe 0.00000000 0.00000000    24
## 12  stress      N    threat 0.00000000 0.00000000    24

All assoc H rates:

# Calculate high confidence H rates
dat_fa = dtest %>%
  filter(cond %in% c('indoor', 'outdoor'),
         acc == 'H') %>%
  mutate(cond = factor(cond),
         acc = factor(acc)) %>%
  group_by(subid, group, shockCond, conf, cond) %>%
  summarise(count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, conf, cond,
           fill = list(count = 0))
head(dat_fa)
## # A tibble: 6 x 6
##    subid   group shockCond   conf    cond count
##   <fctr>  <fctr>    <fctr> <fctr>  <fctr> <dbl>
## 1  ap100 control      safe     Hi  indoor    22
## 2  ap100 control      safe     Hi outdoor    24
## 3  ap100 control      safe     Lo  indoor     3
## 4  ap100 control      safe     Lo outdoor     0
## 5  ap100 control      safe      N  indoor     0
## 6  ap100 control      safe      N outdoor     0
old_counts = dtest %>%
  filter(cond %in% c('indoor', 'outdoor')) %>%
  mutate(cond = factor(cond),
         acc = factor(acc)) %>%
  group_by(subid, group, shockCond, cond) %>%
  summarise(count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, cond,
           fill = list(count = 0))

dat_fa = dat_fa %>% 
  left_join(old_counts %>% rename(old_count = count)) %>%
  mutate(hit_rate = count/old_count)
## Joining, by = c("subid", "group", "shockCond", "cond")
dat_fa %>% group_by(subid, group, conf) %>% 
  summarise(hit_rate = mean(hit_rate)) %>%
  group_by(group, conf) %>%
  summarise(mean(hit_rate), std.error(hit_rate), n())
## Source: local data frame [6 x 5]
## Groups: group [?]
## 
## # A tibble: 6 x 5
##     group   conf `mean(hit_rate)` `std.error(hit_rate)` `n()`
##    <fctr> <fctr>            <dbl>                 <dbl> <int>
## 1 control     Hi        0.4886196            0.04835648    23
## 2 control     Lo        0.1638104            0.02223038    23
## 3 control      N        0.0000000            0.00000000    23
## 4  stress     Hi        0.3016106            0.03293669    24
## 5  stress     Lo        0.2152586            0.02335922    24
## 6  stress      N        0.0000000            0.00000000    24
dat_fa %>% filter(group == 'stress') %>%
  group_by(subid, group, conf, shockCond) %>% 
  summarise(hit_rate = mean(hit_rate)) %>%
  group_by(group, conf, shockCond) %>%
  summarise(mean(hit_rate), std.error(hit_rate), n())
## Source: local data frame [6 x 6]
## Groups: group, conf [?]
## 
## # A tibble: 6 x 6
##    group   conf shockCond `mean(hit_rate)` `std.error(hit_rate)` `n()`
##   <fctr> <fctr>    <fctr>            <dbl>                 <dbl> <int>
## 1 stress     Hi      safe        0.2986777            0.03246858    24
## 2 stress     Hi    threat        0.3045435            0.03488316    24
## 3 stress     Lo      safe        0.2169879            0.02301797    24
## 4 stress     Lo    threat        0.2135294            0.02466803    24
## 5 stress      N      safe        0.0000000            0.00000000    24
## 6 stress      N    threat        0.0000000            0.00000000    24

All assoc error (miss) rates:

# Calculate high confidence H rates
dat_fa = dtest %>%
  filter(cond %in% c('indoor', 'outdoor'),
         acc == 'SM') %>%
  mutate(cond = factor(cond),
         acc = factor(acc)) %>%
  group_by(subid, group, shockCond, conf, cond) %>%
  summarise(count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, conf, cond,
           fill = list(count = 0))
head(dat_fa)
## # A tibble: 6 x 6
##    subid   group shockCond   conf    cond count
##   <fctr>  <fctr>    <fctr> <fctr>  <fctr> <dbl>
## 1  ap100 control      safe     Hi  indoor     3
## 2  ap100 control      safe     Hi outdoor     2
## 3  ap100 control      safe     Lo  indoor     2
## 4  ap100 control      safe     Lo outdoor     4
## 5  ap100 control      safe      N  indoor     0
## 6  ap100 control      safe      N outdoor     0
old_counts = dtest %>%
  filter(cond %in% c('indoor', 'outdoor')) %>%
  mutate(cond = factor(cond),
         acc = factor(acc)) %>%
  group_by(subid, group, shockCond, cond) %>%
  summarise(count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, cond,
           fill = list(count = 0))

dat_fa = dat_fa %>% 
  left_join(old_counts %>% rename(old_count = count)) %>%
  mutate(hit_rate = count/old_count)
## Joining, by = c("subid", "group", "shockCond", "cond")
dat_fa %>% group_by(subid, group, conf) %>% 
  summarise(hit_rate = mean(hit_rate)) %>%
  group_by(group, conf) %>%
  summarise(mean(hit_rate), std.error(hit_rate), n())
## Source: local data frame [6 x 5]
## Groups: group [?]
## 
## # A tibble: 6 x 5
##     group   conf `mean(hit_rate)` `std.error(hit_rate)` `n()`
##    <fctr> <fctr>            <dbl>                 <dbl> <int>
## 1 control     Hi       0.09469007            0.01150091    23
## 2 control     Lo       0.13231420            0.01996173    23
## 3 control      N       0.00000000            0.00000000    23
## 4  stress     Hi       0.09025433            0.01282108    24
## 5  stress     Lo       0.20250565            0.02215405    24
## 6  stress      N       0.00000000            0.00000000    24
dat_fa %>% filter(group == 'stress') %>%
  group_by(subid, group, conf, shockCond) %>% 
  summarise(hit_rate = mean(hit_rate)) %>%
  group_by(group, conf, shockCond) %>%
  summarise(mean(hit_rate), std.error(hit_rate), n())
## Source: local data frame [6 x 6]
## Groups: group, conf [?]
## 
## # A tibble: 6 x 6
##    group   conf shockCond `mean(hit_rate)` `std.error(hit_rate)` `n()`
##   <fctr> <fctr>    <fctr>            <dbl>                 <dbl> <int>
## 1 stress     Hi      safe       0.10026132            0.01646251    24
## 2 stress     Hi    threat       0.08024734            0.01083886    24
## 3 stress     Lo      safe       0.19875750            0.02265572    24
## 4 stress     Lo    threat       0.20625380            0.02357937    24
## 5 stress      N      safe       0.00000000            0.00000000    24
## 6 stress      N    threat       0.00000000            0.00000000    24

Does cortisol affect assoc dprime?

### Does cortisol affect assoc dprime?
d_cort = read.csv('/Volumes/group/awagner/sgagnon/AP/data/cortisol/cort_percentchange_testbaseline.csv')

dprime_cort = dmerge %>% left_join(d_cort)
## Joining, by = c("subid", "group")
str(dprime_cort)
## Classes 'tbl_df', 'tbl' and 'data.frame':    376 obs. of  12 variables:
##  $ subid     : Factor w/ 47 levels "ap100","ap101",..: 1 1 1 1 1 1 1 1 2 2 ...
##  $ group     : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##   ..- attr(*, "contrasts")= num [1:2, 1] 1 -1
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr  "control" "stress"
##   .. .. ..$ : NULL
##  $ shockCond : Factor w/ 2 levels "safe","threat": 1 1 1 1 2 2 2 2 1 1 ...
##   ..- attr(*, "contrasts")= num [1:2, 1] 1 -1
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr  "safe" "threat"
##   .. .. ..$ : NULL
##  $ reps      : Factor w/ 2 levels "2","4": 1 1 2 2 1 1 2 2 1 1 ...
##   ..- attr(*, "contrasts")= num [1:2, 1] -1 1
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr  "2" "4"
##   .. .. ..$ : NULL
##  $ resp      : Factor w/ 2 levels "indoor","outdoor": 1 2 1 2 1 2 1 2 1 2 ...
##   ..- attr(*, "contrasts")= num [1:2, 1] -1 1
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr  "indoor" "outdoor"
##   .. .. ..$ : NULL
##  $ H         : num  0.5 0.556 0.667 0.7 0.476 ...
##  $ SM        : num  0.0556 0.025 0.05 0.1667 0.0476 ...
##  $ dprime    : num  1.59 2.1 2.08 1.49 1.61 ...
##  $ c         : num  0.797 0.91 0.607 0.222 0.864 ...
##  $ X         : int  0 0 0 0 0 0 0 0 1 1 ...
##  $ assay     : Factor w/ 2 levels "IBL","Salimetrics": 1 1 1 1 1 1 1 1 1 1 ...
##  $ log.ug.dL.: num  -7.36 -7.36 -7.36 -7.36 -7.36 ...
contrasts(dprime_cort$shockCond) = c(1,-1)
contrasts(dprime_cort$reps) = c(-1,1)
contrasts(dprime_cort$assay) = c(-1,1)
contrasts(dprime_cort$resp) = c(-1,1); contrasts(dprime_cort$resp)
##         [,1]
## indoor    -1
## outdoor    1
# include group interactions by resp, shockcond, reps
fit = lmer(dprime ~ scale(log.ug.dL.) * (shockCond * reps + resp) + assay+
               (1 + reps + shockCond + resp| subid), data=dprime_cort,
             control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5)))
fit2 = lmer(dprime ~ poly(log.ug.dL.,2) * (shockCond * reps + resp) + assay+
               (1 + reps + shockCond + resp| subid), data=dprime_cort,
             control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5)))
anova(fit, fit2)
## refitting model(s) with ML (instead of REML)
## Data: dprime_cort
## Models:
## object: dprime ~ scale(log.ug.dL.) * (shockCond * reps + resp) + assay + 
## object:     (1 + reps + shockCond + resp | subid)
## ..1: dprime ~ poly(log.ug.dL., 2) * (shockCond * reps + resp) + assay + 
## ..1:     (1 + reps + shockCond + resp | subid)
##        Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(>Chisq)
## object 22 616.46 702.91 -286.23   572.46                         
## ..1    27 621.92 728.01 -283.96   567.92 4.5454      5     0.4738
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: dprime ~ scale(log.ug.dL.) * (shockCond * reps + resp) + assay +  
##     (1 + reps + shockCond + resp | subid)
##    Data: dprime_cort
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 626.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.92749 -0.64163 -0.07639  0.61270  2.58371 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr             
##  subid    (Intercept) 0.5684942 0.75399                   
##           reps1       0.0160436 0.12666   0.71            
##           shockCond1  0.0095079 0.09751   0.39  0.44      
##           resp1       0.0008988 0.02998  -0.12  0.31  0.23
##  Residual             0.1669770 0.40863                   
## Number of obs: 376, groups:  subid, 47
## 
## Fixed effects:
##                                      Estimate Std. Error         df
## (Intercept)                          1.079974   0.114447  45.210000
## scale(log.ug.dL.)                    0.073057   0.112158  44.390000
## shockCond1                          -0.018297   0.025424  45.000000
## reps1                                0.208980   0.028026  45.000000
## resp1                                0.040267   0.021522  45.000000
## assay1                               0.011269   0.100963  44.000000
## shockCond1:reps1                     0.050556   0.021073 186.000000
## scale(log.ug.dL.):shockCond1         0.009607   0.025458  45.000000
## scale(log.ug.dL.):reps1             -0.039233   0.028063  45.000000
## scale(log.ug.dL.):resp1              0.011876   0.021551  45.000000
## scale(log.ug.dL.):shockCond1:reps1  -0.008532   0.021101 186.000000
##                                    t value Pr(>|t|)    
## (Intercept)                          9.436 2.96e-12 ***
## scale(log.ug.dL.)                    0.651   0.5182    
## shockCond1                          -0.720   0.4754    
## reps1                                7.457 2.15e-09 ***
## resp1                                1.871   0.0679 .  
## assay1                               0.112   0.9116    
## shockCond1:reps1                     2.399   0.0174 *  
## scale(log.ug.dL.):shockCond1         0.377   0.7077    
## scale(log.ug.dL.):reps1             -1.398   0.1690    
## scale(log.ug.dL.):resp1              0.551   0.5843    
## scale(log.ug.dL.):shockCond1:reps1  -0.404   0.6864    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##                   (Intr) sc(..L.) shckC1 reps1  resp1  assay1 shC1:1
## scl(lg..L.)       -0.005                                            
## shockCond1         0.208  0.000                                     
## reps1              0.449  0.000    0.163                            
## resp1             -0.023  0.000    0.026  0.042                     
## assay1             0.206 -0.022    0.000  0.000  0.000              
## shckCnd1:r1        0.000  0.000    0.000  0.000  0.000  0.000       
## sc(..L.):C1        0.000  0.212    0.000  0.000  0.000  0.000  0.000
## scl(lg.g.dL.):rp1  0.000  0.459    0.000  0.000  0.000  0.000  0.000
## scl(lg.g.dL.):rs1  0.000 -0.024    0.000  0.000  0.000  0.000  0.000
## s(..L.):C1:        0.000  0.000    0.000  0.000  0.000  0.000  0.000
##                   sc(..L.):C1 scl(lg.g.dL.):rp1 scl(lg.g.dL.):rs1
## scl(lg..L.)                                                      
## shockCond1                                                       
## reps1                                                            
## resp1                                                            
## assay1                                                           
## shckCnd1:r1                                                      
## sc(..L.):C1                                                      
## scl(lg.g.dL.):rp1  0.163                                         
## scl(lg.g.dL.):rs1  0.026       0.042                             
## s(..L.):C1:        0.000       0.000             0.000

1c) Plot item and assoc dprimes

# merge these 2 measures:
item_d = item_d %>% 
  dplyr::select(subid, group, reps, shockCond, dprime) %>%
  group_by(subid, group, reps, shockCond) %>%
  summarise(item_d = mean(dprime))

assoc_d = assoc_d %>% 
  dplyr::select(subid, group, reps, shockCond, dprime) %>%
  group_by(subid, group, reps, shockCond) %>%
  summarise(assoc_d = mean(dprime))

combined_d = item_d %>% left_join(assoc_d) %>% 
  ungroup() %>%
  gather(key = 'cond', value = 'dprime', item_d:assoc_d) %>%
  mutate(cond = factor(cond), reps=factor(reps))
## Joining, by = c("subid", "group", "reps", "shockCond")
combined_d
## # A tibble: 376 x 6
##     subid   group   reps shockCond   cond    dprime
##    <fctr>  <fctr> <fctr>    <fctr> <fctr>     <dbl>
##  1  ap100 control      2      safe item_d 1.5015336
##  2  ap100 control      2    threat item_d 1.5885859
##  3  ap100 control      4      safe item_d 1.6844710
##  4  ap100 control      4    threat item_d 1.8435644
##  5  ap101 control      2      safe item_d 2.4114797
##  6  ap101 control      2    threat item_d 2.6931954
##  7  ap101 control      4      safe item_d 3.4459862
##  8  ap101 control      4    threat item_d 2.8568952
##  9  ap102 control      2      safe item_d 0.8767526
## 10  ap102 control      2    threat item_d 0.8508243
## # ... with 366 more rows
davg = combined_d %>%
  group_by(subid, group, cond, reps) %>%
  summarise(dprime = mean(dprime)) %>% 
  group_by(group, cond, reps) %>%
  summarise(mean = mean(dprime),
            se = std.error(dprime),
            sterr = sd(dprime)/sqrt(n()),
            ci = error <- qt(1-(.05/2),df=n()-1)*sd(dprime)/sqrt(n()),
            sd = sd(dprime),
            n()) %>%
  ungroup() %>%
  mutate(cond = as.character(cond)) %>%
  mutate(cond=replace(cond, cond=='assoc_d', 'Associative'),
         cond=replace(cond, cond=='item_d', 'Item')) %>%
  mutate(cond = factor(cond, levels=c('Item', 'Associative'))) %>%
  mutate(reps = as.character(reps)) %>%
  mutate(reps=replace(reps, reps=='2', 'weak'),
         reps=replace(reps, reps=='4', 'strong')) %>%
  mutate(reps = factor(reps, levels=c('weak', 'strong')))

davg
## # A tibble: 8 x 9
##     group        cond   reps      mean        se     sterr        ci
##    <fctr>      <fctr> <fctr>     <dbl>     <dbl>     <dbl>     <dbl>
## 1 control Associative   weak 1.0971524 0.1564134 0.1564134 0.3243814
## 2 control Associative strong 1.6355152 0.1853442 0.1853442 0.3843803
## 3 control        Item   weak 1.7018254 0.1817859 0.1817859 0.3770009
## 4 control        Item strong 2.0871727 0.1974001 0.1974001 0.4093827
## 5  stress Associative   weak 0.6490942 0.1164531 0.1164531 0.2409017
## 6  stress Associative strong 0.9516674 0.1411232 0.1411232 0.2919356
## 7  stress        Item   weak 1.2568043 0.1108637 0.1108637 0.2293390
## 8  stress        Item strong 1.7006655 0.1382036 0.1382036 0.2858959
## # ... with 2 more variables: sd <dbl>, `n()` <int>
p = ggplot(davg, 
       aes(x=reps, y=mean, group=group, fill=group)) + 
   facet_grid(.~cond, scales = "free_x", space = "free_x") +
    geom_bar(position=position_dodge(), stat="identity") + 
    geom_errorbar(width=0, aes(ymin=mean-se, 
                               ymax=mean+se), size=1.5, position=position_dodge(.9)) +
    scale_fill_manual(values=c('dodgerblue', 'orange')) +
  ylab(expression(paste('Discriminability (',italic("d'"),')')))+
  xlab('Encoding strength') +
    theme(legend.title=element_blank(), axis.title.y=element_text(face="italic"))

ggsave('~/Experiments/AP/figs/AP_behav_dprimes_bystrength.jpeg', dpi=150, width=8, height=4)
p

dcomb = combined_d %>%
  group_by(subid, group, cond, reps) %>%
  summarise(dprime = mean(dprime)) %>% 
  ungroup() %>%
  mutate(cond = as.character(cond)) %>%
  mutate(cond=replace(cond, cond=='assoc_d', 'Associative'),
         cond=replace(cond, cond=='item_d', 'Item')) %>%
  mutate(cond = factor(cond, levels=c('Item', 'Associative'))) %>%
  mutate(reps = as.character(reps)) %>%
  mutate(reps=replace(reps, reps=='2', 'weak'),
         reps=replace(reps, reps=='4', 'strong')) %>%
  mutate(reps = factor(reps, levels=c('weak', 'strong'))) %>%
  ungroup()
dcomb
## # A tibble: 188 x 5
##     subid   group        cond   reps    dprime
##    <fctr>  <fctr>      <fctr> <fctr>     <dbl>
##  1  ap100 control Associative   weak 1.6377555
##  2  ap100 control Associative strong 1.5468521
##  3  ap100 control        Item   weak 1.5450597
##  4  ap100 control        Item strong 1.7640177
##  5  ap101 control Associative   weak 1.3064383
##  6  ap101 control Associative strong 2.8341356
##  7  ap101 control        Item   weak 2.5523376
##  8  ap101 control        Item strong 3.1514407
##  9  ap102 control Associative   weak 0.5144762
## 10  ap102 control Associative strong 1.0402563
## # ... with 178 more rows
p = ggplot(dcomb, 
       aes(x=reps, y=dprime, color=group)) + 
   facet_grid(.~cond) +
   geom_boxplot(position = position_dodge(width = .85),
                outlier.shape = NA) +
  scale_x_discrete(name = "Encoding strength") +
  geom_point(pch = 21, position = position_jitterdodge())+
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  ylab(expression(paste('Discriminability (',italic("d'"),')')))+
  theme(legend.title=element_blank(), axis.title.y=element_text(face="italic"))

ggsave('~/Experiments/AP/figs/AP_behav_dprimes_bystrength_boxplot.jpeg', dpi=150, width=8, height=4)
p

p = ggplot(dcomb, 
       aes(x=reps, y=dprime, color=group)) + 
   facet_grid(.~cond) +
   stat_summary(fun.y = "mean", size = 9, shape=18, alpha=.7,
                geom = "point", position=position_dodge(.9)) +
  scale_x_discrete(name = "Encoding strength") +
  geom_point(pch = 21, position = position_jitterdodge(), alpha=1, size=3)+
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  ylab(expression(paste('Discriminability (',italic("d'"),')')))+
  theme(legend.title=element_blank(), axis.title.y=element_text(face="italic"))
p

ggsave('~/Experiments/AP/figs/AP_behav_dprimes_bystrength_stripplot.jpeg', dpi=150, width=8, height=4)
p

# point plot with points
p = ggplot(dcomb, 
       aes(x=reps, y=dprime, color=group)) + 
   facet_grid(.~cond) +
   # stat_summary(fun.y = "mean", size = 9, shape=18, alpha=.7,
   #              geom = "point", position=position_dodge(.9)) +
  geom_point(pch = 21, position = position_jitterdodge(), 
             alpha=1, size=3)+
  scale_x_discrete(name = "Encoding strength") +
  geom_point(data = davg, aes(y=mean), position=position_dodge(.9), 
             alpha=.7, size = 3, shape=18) +
  geom_errorbar(data = davg, width=0,
                aes(y=mean, ymin=mean-se, ymax=mean+se),
                size=2, position=position_dodge(.9), alpha=.7) +
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  ylab(expression(paste('Discriminability (',italic("d'"),')')))+
  theme(legend.title=element_blank(), axis.title.y=element_text(face="italic"))
## Warning: Ignoring unknown aesthetics: y
p

p = ggplot(dcomb, 
       aes(x=reps, y=dprime, color=group)) + 
   facet_grid(.~cond) +
  geom_point(pch = 21, position = position_jitterdodge(), 
             alpha=.5, size=2)+
  scale_x_discrete(name = "Encoding strength") +
  geom_point(data = davg, aes(y=mean), position=position_dodge(.9), 
             alpha=.8, size = 2.5, shape=19) +
  geom_errorbar(data = davg, width=0,
                aes(y=mean, ymin=mean-se, ymax=mean+se),
                size=1.5, position=position_dodge(.9), alpha=.8) +
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  ylab(expression(paste('Discriminability (',italic("d'"),')')))+
  theme(legend.title=element_blank(), axis.title.y=element_text(face="italic"))
## Warning: Ignoring unknown aesthetics: y
ggsave('~/Experiments/AP/figs/AP_behav_dprimes_bystrength_stripplot_se.jpeg', dpi=600, width=8, height=4)
p

p = ggplot(dcomb, 
       aes(x=reps, y=dprime, color=group)) + 
   facet_grid(.~cond) +
  geom_point(pch = 19, position = position_jitterdodge(), 
             alpha=.2, size=1.5)+
  scale_x_discrete(name = "Encoding strength") +
  geom_point(data = davg, aes(y=mean), position=position_dodge(.9), 
             alpha=1, size = 2.5, shape=19) +
  geom_errorbar(data = davg, width=0,
                aes(y=mean, ymin=mean-se, ymax=mean+se),
                size=1.5, position=position_dodge(.9), alpha=1) +
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  ylab(expression(paste('Discriminability (',italic("d'"),')')))+
  theme_classic(base_size = 14)+
  theme(legend.title=element_blank(), 
        strip.text = element_text(size=14),
        strip.background = element_rect(colour="white", fill="white"),
        axis.title.y=element_text(face="italic"))
## Warning: Ignoring unknown aesthetics: y
ggsave('~/Experiments/AP/figs/AP_behav_dprimes_bystrength_stripplot_se_v2.jpeg', dpi=600, width=6.69, height=3)
ggsave('~/Dropbox/Stanford/Papers/AP/Figures/AP_figure2.tiff', dpi=600, width=6.69, height=3)
p

ann_text <- data.frame(reps = c(.75, 1.25), dprime = c(4, 3.5),
                       group=c('control', 'stress'),
                        lab=c("control", "stress"),
                        cond = factor(c('Item'), levels = c("Item", "Associative")))
# 95% CI
p = ggplot(dcomb, 
       aes(x=reps, y=dprime, color=group)) + 
   facet_grid(.~cond) +
  geom_point(pch = 19, position = position_jitterdodge(), 
             alpha=.2, size=1.5)+
  scale_x_discrete(name = "Encoding strength") +
  geom_errorbar(data = davg, width=0,
                aes(y=mean, ymin=mean-ci, ymax=mean+ci),
                size=1.5, position=position_dodge(.9), alpha=1) +
  geom_point(data = davg, aes(y=mean), position=position_dodge(.9), 
             alpha=1, size = 4, shape=1) +
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  ylab(expression(paste('Discriminability (',italic("d'"),')')))+
  geom_text(data = ann_text,aes(label =lab)) +
  theme_classic(base_size = 14)+
  theme(legend.title=element_blank(), 
        strip.background = element_rect(colour="white", fill="white"),
        legend.position="none",
        axis.title.y=element_text(face="italic"))
## Warning: Ignoring unknown aesthetics: y
ggsave('~/Experiments/AP/figs/AP_behav_dprimes_bystrength_stripplot_95ci_v2.jpeg', dpi=600, width=6.69, height=3)
ggsave('~/Dropbox/Stanford/Papers/AP/Figures/AP_figure2_95ci.jpg', dpi=600, width=6.69, height=3)
p

Just assoc plot

# p = ggplot(davg %>% filter(cond == 'associative'), 
#        aes(x=reps, y=mean, group=group, fill=group)) + 
#     geom_bar(position=position_dodge(), stat="identity") + 
#     geom_errorbar(width=0, aes(ymin=mean-se, 
#                                ymax=mean+se), size=1.5, position=position_dodge(.9)) +
#     scale_fill_manual(values=c('dodgerblue', 'orange')) +
#   ylab(expression(paste('Associative ',italic("d'"))))+
#   xlab('Encoding strength') +
#   ylim(0, 1.9) +
#     theme(legend.title=element_blank(), axis.title.y=element_text(face="italic"))
# 
# ggsave('~/Dropbox/Stanford/Papers/Dissertation/Figures_defense/AP_behav_assocdprime_bystrength.jpeg', 
#        dpi=300, width=6, height=4)
# p
davg = combined_d %>%
  filter(group == 'stress') %>%
  group_by(subid, group, cond, reps, shockCond) %>%
  summarise(dprime = mean(dprime)) %>% 
  group_by(group, cond, reps, shockCond) %>%
  summarise(mean = mean(dprime),
            se = std.error(dprime),
            sterr = sd(dprime)/sqrt(n()),
            n()) %>%
  ungroup() %>%
  mutate(cond = as.character(cond)) %>%
  mutate(cond=replace(cond, cond=='assoc_d', 'associative'),
         cond=replace(cond, cond=='item_d', 'item')) %>%
  mutate(cond = factor(cond, levels=c('item', 'associative'))) %>%
  mutate(reps = as.character(reps)) %>%
  mutate(reps=replace(reps, reps=='2', 'weak'),
         reps=replace(reps, reps=='4', 'strong')) %>%
  mutate(reps = factor(reps, levels=c('weak', 'strong')))

davg
## # A tibble: 8 x 8
##    group        cond   reps shockCond      mean        se     sterr `n()`
##   <fctr>      <fctr> <fctr>    <fctr>     <dbl>     <dbl>     <dbl> <int>
## 1 stress associative   weak      safe 0.5652593 0.1241485 0.1241485    24
## 2 stress associative   weak    threat 0.7329291 0.1265974 0.1265974    24
## 3 stress associative strong      safe 0.9518255 0.1692885 0.1692885    24
## 4 stress associative strong    threat 0.9515093 0.1345798 0.1345798    24
## 5 stress        item   weak      safe 1.2597242 0.1353836 0.1353836    24
## 6 stress        item   weak    threat 1.2538845 0.1119375 0.1119375    24
## 7 stress        item strong      safe 1.7282156 0.1638694 0.1638694    24
## 8 stress        item strong    threat 1.6731154 0.1295086 0.1295086    24
p=ggplot(davg, 
       aes(x=reps, y=mean, group=shockCond, fill=shockCond)) + 
   facet_grid(.~cond, scales = "free_x", space = "free_x") +
    geom_bar(position=position_dodge(), stat="identity") + 
    geom_errorbar(width=0, aes(ymin=mean-se, 
                               ymax=mean+se), size=1.5, position=position_dodge(.9)) +
    scale_fill_manual(values=c('mediumpurple', 'darkorange')) +
  ylab(expression(paste('Discriminability (',italic("d'"),')')))+
  xlab('Encoding strength') +
    theme(legend.title=element_blank(), axis.title.y=element_text(face="italic"))

ggsave('~/Experiments/AP/figs/AP_behav_dprimes_stress_byshockCond.jpeg', dpi=150, width=8, height=4)
p

Stress: within-participant standard error/95% CI (if all subjs)

davg = combined_d %>%
  filter(group == 'stress') %>%
  group_by(subid, group, cond, reps, shockCond) %>%
  summarise(dprime = mean(dprime)) 
davg
## Source: local data frame [192 x 6]
## Groups: subid, group, cond, reps [?]
## 
## # A tibble: 192 x 6
##     subid  group    cond   reps shockCond     dprime
##    <fctr> <fctr>  <fctr> <fctr>    <fctr>      <dbl>
##  1  ap150 stress assoc_d      2      safe  1.6753826
##  2  ap150 stress assoc_d      2    threat  0.9467194
##  3  ap150 stress assoc_d      4      safe  1.5926593
##  4  ap150 stress assoc_d      4    threat  1.2552104
##  5  ap150 stress  item_d      2      safe  1.3091717
##  6  ap150 stress  item_d      2    threat  1.9073581
##  7  ap150 stress  item_d      4      safe  1.6567948
##  8  ap150 stress  item_d      4    threat  1.3816142
##  9  ap151 stress assoc_d      2      safe -0.1561806
## 10  ap151 stress assoc_d      2    threat  0.0000000
## # ... with 182 more rows
dfwc = summarySEwithin(davg, measurevar="dprime", withinvars=c("cond", "reps", "shockCond"),
                       idvar="subid", na.rm=TRUE, conf.interval=.95) %>%
  ungroup() %>%
  mutate(cond = as.character(cond)) %>%
  mutate(cond=replace(cond, cond=='assoc_d', 'Associative'),
         cond=replace(cond, cond=='item_d', 'Item')) %>%
  mutate(cond = factor(cond, levels=c('Item', 'Associative'))) %>%
  mutate(reps = as.character(reps)) %>%
  mutate(reps=replace(reps, reps=='2', 'weak'),
         reps=replace(reps, reps=='4', 'strong')) %>%
  mutate(reps = factor(reps, levels=c('weak', 'strong')))

dfwc
##          cond   reps shockCond  N    dprime dprime_norm        sd
## 1 Associative   weak      safe 24 0.5652593   0.5652593 0.3927540
## 2 Associative   weak    threat 24 0.7329291   0.7329291 0.3658351
## 3 Associative strong      safe 24 0.9518255   0.9518255 0.5436313
## 4 Associative strong    threat 24 0.9515093   0.9515093 0.3729508
## 5        Item   weak      safe 24 1.2597242   1.2597242 0.4441552
## 6        Item   weak    threat 24 1.2538845   1.2538845 0.3616066
## 7        Item strong      safe 24 1.7282156   1.7282156 0.5007407
## 8        Item strong    threat 24 1.6731154   1.6731154 0.4045086
##           se        ci
## 1 0.08017058 0.1658455
## 2 0.07467578 0.1544786
## 3 0.11096828 0.2295554
## 4 0.07612826 0.1574833
## 5 0.09066279 0.1875503
## 6 0.07381263 0.1526931
## 7 0.10221327 0.2114443
## 8 0.08256997 0.1708090
p=ggplot(dfwc, 
       aes(x=reps, y=dprime, group=shockCond, fill=shockCond)) + 
   facet_grid(.~cond, scales = "free_x", space = "free_x") +
    geom_bar(position=position_dodge(), stat="identity") + 
    geom_errorbar(width=0, aes(ymin=dprime-se, 
                               ymax=dprime+se), size=1.5, position=position_dodge(.9)) +
    scale_fill_manual(values=c('mediumpurple', 'darkorange')) +
  ylab(expression(paste('Discriminability (',italic("d'"),')')))+
  xlab('Encoding strength') +
    theme(legend.title=element_blank(), axis.title.y=element_text(face="italic"))

ggsave('~/Experiments/AP/figs/AP_behav_dprimes_stress_byshockCond_withinsubjerrorbars.jpeg', dpi=300, width=8, height=4)
p

### include points for each subj
dcomb = combined_d %>%
  filter(group == 'stress') %>%
  group_by(subid, group, shockCond, cond, reps) %>%
  summarise(dprime = mean(dprime)) %>% 
  ungroup() %>%
  mutate(cond = as.character(cond)) %>%
  mutate(cond=replace(cond, cond=='assoc_d', 'Associative'),
         cond=replace(cond, cond=='item_d', 'Item')) %>%
  mutate(cond = factor(cond, levels=c('Item', 'Associative'))) %>%
  mutate(reps = as.character(reps)) %>%
  mutate(reps=replace(reps, reps=='2', 'weak'),
         reps=replace(reps, reps=='4', 'strong')) %>%
  mutate(reps = factor(reps, levels=c('weak', 'strong'))) %>%
  ungroup()
dcomb
## # A tibble: 192 x 6
##     subid  group shockCond        cond   reps     dprime
##    <fctr> <fctr>    <fctr>      <fctr> <fctr>      <dbl>
##  1  ap150 stress      safe Associative   weak  1.6753826
##  2  ap150 stress      safe Associative strong  1.5926593
##  3  ap150 stress      safe        Item   weak  1.3091717
##  4  ap150 stress      safe        Item strong  1.6567948
##  5  ap150 stress    threat Associative   weak  0.9467194
##  6  ap150 stress    threat Associative strong  1.2552104
##  7  ap150 stress    threat        Item   weak  1.9073581
##  8  ap150 stress    threat        Item strong  1.3816142
##  9  ap151 stress      safe Associative   weak -0.1561806
## 10  ap151 stress      safe Associative strong  0.1796097
## # ... with 182 more rows
p = ggplot(dcomb, 
       aes(x=reps, y=dprime, color=shockCond)) + 
   facet_grid(.~cond) +
  geom_point(pch = 19, position = position_jitterdodge(), 
             alpha=.2, size=1.5)+
  scale_x_discrete(name = "Encoding strength") +
  geom_point(data = dfwc, aes(y=dprime), position=position_dodge(.9), 
             alpha=1, size = 2.5, shape=19) +
  geom_errorbar(data = dfwc, width=0,
                aes(y=dprime, ymin=dprime-ci, ymax=dprime+ci),
                size=1.5, position=position_dodge(.9), alpha=1) +
  scale_color_manual(values=c('#0072b2', '#d55e00')) +
  ylab(expression(paste('Discriminability (',italic("d'"),')')))+
  theme_classic(base_size = 14)+
  theme(legend.title=element_blank(), 
        strip.text = element_text(size=14),
        strip.background = element_rect(colour="white", fill="white"),
        axis.title.y=element_text(face="italic"))
## Warning: Ignoring unknown aesthetics: y
p

ggsave('~/Dropbox/Stanford/Papers/AP/Figures/AP_supp_figure2.tiff', dpi=600, width=6.69, height=3)
ggsave('~/Dropbox/Stanford/Papers/AP/Figures/AP_supp_figure2_dpi150.tiff', dpi=150, width=6.69, height=3)

1d) RT

HC hit, LC hit, CR

dt = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/mvpa/notebooks/ap_behav.csv')
with(dt, table(shockTrial, mem_conditions, group))
## , , group = control-fmri
## 
##           mem_conditions
## shockTrial   CR   FA itemhit_lo    M nuisance sourcehit sourcemiss_hi
##          0 1254  622       1126  426       75      1833           355
##          1   21   13         16    3        2        31             6
## 
## , , group = stress-fmri
## 
##           mem_conditions
## shockTrial   CR   FA itemhit_lo    M nuisance sourcehit sourcemiss_hi
##          0 1204  700       1606  682      207      1164           348
##          1    0    0          0    0       95         0             0
# Get mean of median RT by condition, only include subjs w/more than 5 trials/cond
drt = dt %>%
  filter(mem_conditions %in% c("sourcehit", 'CR', 'itemhit_lo')) %>%
  group_by(group, subid, mem_conditions) %>%
  summarise(rt=median(respRT), rt_sd = sd(respRT), n=n()) %>%
  filter(n > 5) %>% 
  group_by(group, mem_conditions) %>%
  summarise(mean=mean(rt), se=std.error(rt), n()) %>%
  ungroup() %>%
  mutate(group = as.character(group),
         group = replace(group, group == 'control-fmri', 'control'),
         group = replace(group, group == 'stress-fmri', 'stress'),
         mem_conditions = as.character(mem_conditions),
         mem_conditions = replace(mem_conditions, mem_conditions=='sourcehit', 'HC\nassoc hit'),
         mem_conditions = replace(mem_conditions, mem_conditions=='itemhit_lo', 'LC\nitem hit'),
         mem_conditions = factor(mem_conditions, levels=c('HC\nassoc hit',
                                                          'LC\nitem hit', 
                                                          'CR')))
drt
## # A tibble: 6 x 5
##     group mem_conditions     mean         se `n()`
##     <chr>         <fctr>    <dbl>      <dbl> <int>
## 1 control             CR 2.011815 0.07130370    23
## 2 control    LC
## item hit 2.568783 0.12211904    21
## 3 control   HC
## assoc hit 2.221578 0.07417229    23
## 4  stress             CR 1.832327 0.07363891    24
## 5  stress    LC
## item hit 2.393730 0.08213239    22
## 6  stress   HC
## assoc hit 2.271007 0.07712911    22
p1=ggplot(drt, 
       aes(x=mem_conditions, y=mean, group=group, color=group)) + 
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=mean-se, 
                               ymax=mean+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
    scale_color_manual(values=c('dodgerblue', 'orange')) +
  ylab('Median RT (s)')+
  xlab('') +
  theme(legend.title = element_blank(),
        legend.position = c(0.9, 0.8))
p1

ggsave('~/Experiments/AP/figs/AP_behav_rt_groupXcond.jpeg', dpi=150, width=6, height=4)
p1

HC assoc hit RT - all trials

drt = dt %>%
  filter(mem_conditions %in% c("sourcehit")) %>% # need at least 6 trials/bin
  group_by(group, subid, mem_conditions) %>%
  summarise(n=n()) %>%
  ungroup() %>%
  mutate(mem_conditions = factor(mem_conditions)) %>%
  complete(nesting(group, subid), mem_conditions, fill=list(n=0))
sub_list = drt %>% filter(n < 6) %>% ungroup %>% pull(subid) %>% unique()
sub_list
## [1] ap151 ap156
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
# look at mean trial counts/cond/group
drt %>%
  filter(!subid %in% sub_list) %>% # need at least 6 trials/bin
  group_by(group, mem_conditions) %>%
  summarise(mean=mean(n), sd=sd(n), n=n())
## Source: local data frame [2 x 5]
## Groups: group [?]
## 
## # A tibble: 2 x 5
##          group mem_conditions     mean       sd     n
##         <fctr>         <fctr>    <dbl>    <dbl> <int>
## 1 control-fmri      sourcehit 81.04348 38.57163    23
## 2  stress-fmri      sourcehit 52.54545 23.32938    22
# get medians/sds
head(dt)
##   X run trial   onset duration shockCond shockTrial  target      associate
## 1 0   1     1 12.0191  10.6661      safe          0  BANDIT       cemetery
## 2 1   1     2 22.7129   9.1242      safe          0  WALRUS           foil
## 3 2   1     3 31.8642   9.4224      safe          0  VIOLIN    throne_room
## 4 3   1     4 41.3132  11.3389      safe          0   MEDAL       hayfield
## 5 4   1     5 52.6786   9.7644      safe          0  MANURE         canyon
## 6 5   1     6 62.4701   9.1180      safe          0 SARDINE mountain_snowy
##      resp acc accSpec respRT subid        group remove anxious happy safe
## 1  indoor  SM  SMO_Hi 2.1094 ap100 control-fmri     NA       3     2    3
## 2    foil  CR      CR 1.7773 ap100 control-fmri     NA       3     2    3
## 3  indoor   H   HI_Hi 1.6804 ap100 control-fmri     NA       3     2    3
## 4 outdoor   H   HO_Hi 1.7268 ap100 control-fmri     NA       3     2    3
## 5 outdoor   H   HO_Hi 1.3734 ap100 control-fmri     NA       3     2    3
## 6 outdoor   H   HO_Hi 2.1476 ap100 control-fmri     NA       3     2    3
##   stressed life_stress sleep cond_orig    cond reps shock_and_post conf
## 1        3           4   4.5      TO_4 outdoor    4              0   Hi
## 2        3           4   4.5       F_0    foil    0              0    N
## 3        3           4   4.5      TI_2  indoor    2              0   Hi
## 4        3           4   4.5      TO_2 outdoor    2              0   Hi
## 5        3           4   4.5      TO_2 outdoor    2              0   Hi
## 6        3           4   4.5      TO_4 outdoor    4              0   Hi
##   onset_adj mem_conditions obj_conditions onset_code        rt_z
## 1    0.0191  sourcemiss_hi            old    itemhit -1.20388009
## 2   10.7129             CR            new         CR -0.12867526
## 3   19.8642      sourcehit            old  sourcehit -0.74601988
## 4   29.3132      sourcehit            old  sourcehit -0.67385952
## 5   40.6786      sourcehit            old  sourcehit -1.22346016
## 6   50.4701      sourcehit            old  sourcehit -0.01943975
##   mem_conditions_byrep onset_code_byrep
## 1      sourcemiss_hi-4        itemhit-4
## 2                 CR-0             CR-0
## 3          sourcehit-2      sourcehit-2
## 4          sourcehit-2      sourcehit-2
## 5          sourcehit-2      sourcehit-2
## 6          sourcehit-4      sourcehit-4
drt = dt %>%
  filter(mem_conditions %in% c("sourcehit"),
         !subid %in% sub_list) %>%
  group_by(group, subid, mem_conditions) %>%
  summarise(rt=median(respRT), rt_sd = sd(respRT), n=n())
min(drt$n)
## [1] 8
drt %>% group_by(mem_conditions, group) %>% summarise(mean(rt), sd(rt), mean(rt_sd), n())
## Source: local data frame [2 x 6]
## Groups: mem_conditions [?]
## 
## # A tibble: 2 x 6
##   mem_conditions        group `mean(rt)`  `sd(rt)` `mean(rt_sd)` `n()`
##           <fctr>       <fctr>      <dbl>     <dbl>         <dbl> <int>
## 1      sourcehit control-fmri   2.221578 0.3557178     0.5505749    23
## 2      sourcehit  stress-fmri   2.271007 0.3617676     0.5854840    22
# median
bartlett.test(rt ~ group, data=drt %>% filter(mem_conditions == 'sourcehit'))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  rt by group
## Bartlett's K-squared = 0.0059736, df = 1, p-value = 0.9384
t.test(rt ~ group, data=drt %>% filter(mem_conditions == 'sourcehit'), var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  rt by group
## t = -0.4621, df = 43, p-value = 0.6463
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2651454  0.1662882
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.221578                   2.271007
# sd
bartlett.test(rt_sd ~ group, data=drt %>% filter(mem_conditions == 'sourcehit'))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  rt_sd by group
## Bartlett's K-squared = 1.9735, df = 1, p-value = 0.1601
t.test(rt_sd ~ group, data=drt %>% filter(mem_conditions == 'sourcehit'), var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  rt_sd by group
## t = -1.0962, df = 43, p-value = 0.2791
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.09913017  0.02931212
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                  0.5505749                  0.5854840

RT: HC assoc hits vs. CRs

Calculate median/SDs:

## [1] ap151 ap156
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
## Source: local data frame [4 x 5]
## Groups: group [?]
## 
## # A tibble: 4 x 5
##          group mem_conditions     mean       sd     n
##         <fctr>         <fctr>    <dbl>    <dbl> <int>
## 1 control-fmri             CR 55.43478 20.08805    23
## 2 control-fmri      sourcehit 81.04348 38.57163    23
## 3  stress-fmri             CR 51.77273 17.56331    22
## 4  stress-fmri      sourcehit 52.54545 23.32938    22
##   X run trial   onset duration shockCond shockTrial  target      associate
## 1 0   1     1 12.0191  10.6661      safe          0  BANDIT       cemetery
## 2 1   1     2 22.7129   9.1242      safe          0  WALRUS           foil
## 3 2   1     3 31.8642   9.4224      safe          0  VIOLIN    throne_room
## 4 3   1     4 41.3132  11.3389      safe          0   MEDAL       hayfield
## 5 4   1     5 52.6786   9.7644      safe          0  MANURE         canyon
## 6 5   1     6 62.4701   9.1180      safe          0 SARDINE mountain_snowy
##      resp acc accSpec respRT subid        group remove anxious happy safe
## 1  indoor  SM  SMO_Hi 2.1094 ap100 control-fmri     NA       3     2    3
## 2    foil  CR      CR 1.7773 ap100 control-fmri     NA       3     2    3
## 3  indoor   H   HI_Hi 1.6804 ap100 control-fmri     NA       3     2    3
## 4 outdoor   H   HO_Hi 1.7268 ap100 control-fmri     NA       3     2    3
## 5 outdoor   H   HO_Hi 1.3734 ap100 control-fmri     NA       3     2    3
## 6 outdoor   H   HO_Hi 2.1476 ap100 control-fmri     NA       3     2    3
##   stressed life_stress sleep cond_orig    cond reps shock_and_post conf
## 1        3           4   4.5      TO_4 outdoor    4              0   Hi
## 2        3           4   4.5       F_0    foil    0              0    N
## 3        3           4   4.5      TI_2  indoor    2              0   Hi
## 4        3           4   4.5      TO_2 outdoor    2              0   Hi
## 5        3           4   4.5      TO_2 outdoor    2              0   Hi
## 6        3           4   4.5      TO_4 outdoor    4              0   Hi
##   onset_adj mem_conditions obj_conditions onset_code        rt_z
## 1    0.0191  sourcemiss_hi            old    itemhit -1.20388009
## 2   10.7129             CR            new         CR -0.12867526
## 3   19.8642      sourcehit            old  sourcehit -0.74601988
## 4   29.3132      sourcehit            old  sourcehit -0.67385952
## 5   40.6786      sourcehit            old  sourcehit -1.22346016
## 6   50.4701      sourcehit            old  sourcehit -0.01943975
##   mem_conditions_byrep onset_code_byrep
## 1      sourcemiss_hi-4        itemhit-4
## 2                 CR-0             CR-0
## 3          sourcehit-2      sourcehit-2
## 4          sourcehit-2      sourcehit-2
## 5          sourcehit-2      sourcehit-2
## 6          sourcehit-4      sourcehit-4

Median RT: SH vs. CR

contrasts(drt$group) = c(1,-1); contrasts(drt$group)
##              [,1]
## control-fmri    1
## stress-fmri    -1
contrasts(drt$mem_conditions) = c(-1,1); contrasts(drt$mem_conditions)
##           [,1]
## CR          -1
## sourcehit    1
fit = lmer(rt ~ group * mem_conditions + (1|subid), data=drt, REML=TRUE) # not enough obs for RE
# plot(fit) # these look fine, not log transforming rt
# hist(resid(fit))
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt ~ group * mem_conditions + (1 | subid)
##    Data: drt
## 
## REML criterion at convergence: 73.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7336 -0.4366 -0.0984  0.3634  3.7289 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.05504  0.2346  
##  Residual             0.06917  0.2630  
## Number of obs: 90, groups:  subid, 45
## 
## Fixed effects:
##                        Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)             2.09345    0.04464 43.00000  46.897  < 2e-16 ***
## group1                  0.02324    0.04464 43.00000   0.521   0.6053    
## mem_conditions1         0.15284    0.02773 43.00000   5.512 1.87e-06 ***
## group1:mem_conditions1 -0.04796    0.02773 43.00000  -1.729   0.0909 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 mm_cn1
## group1      -0.022              
## mem_cndtns1  0.000  0.000       
## grp1:mm_cn1  0.000  0.000 -0.022
drt %>% group_by(mem_conditions, group) %>% summarise(mean(rt), sd(rt), n())
## Source: local data frame [4 x 5]
## Groups: mem_conditions [?]
## 
## # A tibble: 4 x 5
##   mem_conditions        group `mean(rt)`  `sd(rt)` `n()`
##           <fctr>       <fctr>      <dbl>     <dbl> <int>
## 1             CR control-fmri   2.011815 0.3419605    23
## 2             CR  stress-fmri   1.869418 0.3503218    22
## 3      sourcehit control-fmri   2.221578 0.3557178    23
## 4      sourcehit  stress-fmri   2.271007 0.3617676    22
drt %>% group_by(mem_conditions) %>% summarise(mean(rt), sd(rt), n())
## # A tibble: 2 x 4
##   mem_conditions `mean(rt)`  `sd(rt)` `n()`
##           <fctr>      <dbl>     <dbl> <int>
## 1             CR   1.942199 0.3496053    45
## 2      sourcehit   2.245743 0.3554651    45
bartlett.test(rt ~ group, data=drt %>% filter(mem_conditions == 'sourcehit'))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  rt by group
## Bartlett's K-squared = 0.0059736, df = 1, p-value = 0.9384
t.test(rt ~ group, data=drt %>% filter(mem_conditions == 'sourcehit'), var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  rt by group
## t = -0.4621, df = 43, p-value = 0.6463
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2651454  0.1662882
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.221578                   2.271007
bartlett.test(rt ~ group, data=drt %>% filter(mem_conditions == 'CR'))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  rt by group
## Bartlett's K-squared = 0.012258, df = 1, p-value = 0.9118
t.test(rt ~ group, data=drt %>% filter(mem_conditions == 'CR'), var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  rt by group
## t = 1.3798, df = 43, p-value = 0.1748
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.06573243  0.35052650
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.011815                   1.869418
t.test(rt ~ mem_conditions, data=drt %>% filter(group == 'control-fmri'), 
       var.equal=TRUE, paired=TRUE)
## 
##  Paired t-test
## 
## data:  rt by mem_conditions
## t = -4.3337, df = 22, p-value = 0.000267
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.3101443 -0.1093818
## sample estimates:
## mean of the differences 
##               -0.209763
t.test(rt ~ mem_conditions, data=drt %>% filter(group == 'stress-fmri'), 
       var.equal=TRUE, paired=TRUE)
## 
##  Paired t-test
## 
## data:  rt by mem_conditions
## t = -3.9552, df = 21, p-value = 0.0007231
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.6127415 -0.1904358
## sample estimates:
## mean of the differences 
##              -0.4015886

SD RT: SH vs. CR

contrasts(drt$group) = c(1,-1); contrasts(drt$group)
##              [,1]
## control-fmri    1
## stress-fmri    -1
contrasts(drt$mem_conditions) = c(-1,1); contrasts(drt$mem_conditions)
##           [,1]
## CR          -1
## sourcehit    1
head(drt)
## Source: local data frame [6 x 6]
## Groups: group, subid [3]
## 
## # A tibble: 6 x 6
##          group  subid mem_conditions     rt     rt_sd     n
##         <fctr> <fctr>         <fctr>  <dbl>     <dbl> <int>
## 1 control-fmri  ap100             CR 1.8108 0.4384731    63
## 2 control-fmri  ap100      sourcehit 2.0958 0.6430124    89
## 3 control-fmri  ap101             CR 2.2218 0.5597954    82
## 4 control-fmri  ap101      sourcehit 1.9797 0.5214043   105
## 5 control-fmri  ap102             CR 1.8402 0.6555323    23
## 6 control-fmri  ap102      sourcehit 1.9995 0.5680501    68
# hist(d$rt_sd)
fit = lmer(rt_sd ~ group * mem_conditions + (1|subid), data=drt, REML=TRUE) # not enough obs for RE
# plot(fit)
# hist(resid(fit))
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt_sd ~ group * mem_conditions + (1 | subid)
##    Data: drt
## 
## REML criterion at convergence: -90.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.91159 -0.55877 -0.02644  0.55570  2.64843 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.005684 0.07539 
##  Residual             0.011864 0.10892 
## Number of obs: 90, groups:  subid, 45
## 
## Fixed effects:
##                         Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)             0.582750   0.016070 43.000000  36.262   <2e-16 ***
## group1                 -0.010910   0.016070 43.000000  -0.679    0.501    
## mem_conditions1        -0.014720   0.011484 43.000000  -1.282    0.207    
## group1:mem_conditions1 -0.006545   0.011484 43.000000  -0.570    0.572    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 mm_cn1
## group1      -0.022              
## mem_cndtns1  0.000  0.000       
## grp1:mm_cn1  0.000  0.000 -0.022
drt %>% group_by(mem_conditions, group) %>% summarise(mean(rt_sd), sd(rt_sd), n())
## Source: local data frame [4 x 5]
## Groups: mem_conditions [?]
## 
## # A tibble: 4 x 5
##   mem_conditions        group `mean(rt_sd)` `sd(rt_sd)` `n()`
##           <fctr>       <fctr>         <dbl>       <dbl> <int>
## 1             CR control-fmri     0.5931054  0.16281772    23
## 2             CR  stress-fmri     0.6018348  0.14402301    22
## 3      sourcehit control-fmri     0.5505749  0.08972954    23
## 4      sourcehit  stress-fmri     0.5854840  0.12212281    22
bartlett.test(rt_sd ~ group, data=drt %>% filter(mem_conditions == 'sourcehit'))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  rt_sd by group
## Bartlett's K-squared = 1.9735, df = 1, p-value = 0.1601
t.test(rt ~ group, data=drt %>% filter(mem_conditions == 'sourcehit'), var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  rt by group
## t = -0.4621, df = 43, p-value = 0.6463
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2651454  0.1662882
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.221578                   2.271007

RT: HC assoc hit vs. item hits

Calculate median/SDs:

## [1] ap104 ap116 ap151 ap156 ap160 ap169
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
## Source: local data frame [4 x 5]
## Groups: group [?]
## 
## # A tibble: 4 x 5
##          group mem_conditions     mean       sd     n
##         <fctr>         <fctr>    <dbl>    <dbl> <int>
## 1 control-fmri     itemhit_lo 54.23810 31.25845    21
## 2 control-fmri      sourcehit 74.71429 33.95312    21
## 3  stress-fmri     itemhit_lo 67.10000 23.74846    20
## 4  stress-fmri      sourcehit 51.70000 24.14016    20
## [1] 8

Median RT: SH vs. IH

contrasts(d$group) = c(1,-1); contrasts(d$group)
##              [,1]
## control-fmri    1
## stress-fmri    -1
contrasts(d$mem_conditions) = c(1,-1); contrasts(d$mem_conditions)
##            [,1]
## itemhit_lo    1
## sourcehit    -1
fit = lmer(rt ~ group * mem_conditions + (1|subid), data=d, REML=TRUE) # not enough obs for RE
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt ~ group * mem_conditions + (1 | subid)
##    Data: d
## 
## REML criterion at convergence: 94.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.15494 -0.51267  0.06231  0.38446  2.52689 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.08562  0.2926  
##  Residual             0.09296  0.3049  
## Number of obs: 82, groups:  subid, 41
## 
## Fixed effects:
##                        Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)             2.38756    0.05678 39.00000  42.049  < 2e-16 ***
## group1                  0.02222    0.05678 39.00000   0.391  0.69770    
## mem_conditions1         0.11740    0.03368 39.00000   3.486  0.00123 ** 
## group1:mem_conditions1  0.04161    0.03368 39.00000   1.235  0.22404    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 mm_cn1
## group1      -0.024              
## mem_cndtns1  0.000  0.000       
## grp1:mm_cn1  0.000  0.000 -0.024
d %>% group_by(group, mem_conditions) %>% summarise(mean(rt), sd(rt), n())
## Source: local data frame [4 x 5]
## Groups: group [?]
## 
## # A tibble: 4 x 5
##          group mem_conditions `mean(rt)`  `sd(rt)` `n()`
##         <fctr>         <fctr>      <dbl>     <dbl> <int>
## 1 control-fmri     itemhit_lo   2.568783 0.5596197    21
## 2 control-fmri      sourcehit   2.250767 0.3590183    21
## 3  stress-fmri     itemhit_lo   2.441125 0.3633611    20
## 4  stress-fmri      sourcehit   2.289553 0.3684635    20
d %>% group_by(mem_conditions) %>% summarise(mean(rt), sd(rt), n())
## # A tibble: 2 x 4
##   mem_conditions `mean(rt)`  `sd(rt)` `n()`
##           <fctr>      <dbl>     <dbl> <int>
## 1     itemhit_lo   2.506511 0.4727320    41
## 2      sourcehit   2.269687 0.3596121    41

SD RT: SH vs. CR

contrasts(d$mem_conditions)
##            [,1]
## itemhit_lo    1
## sourcehit    -1
fit = lmer(rt_sd ~ group * mem_conditions + (1|subid), data=d, REML=TRUE) # not enough obs for RE
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt_sd ~ group * mem_conditions + (1 | subid)
##    Data: d
## 
## REML criterion at convergence: -107.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.5836 -0.5429 -0.1018  0.5050  2.0233 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.009172 0.09577 
##  Residual             0.005804 0.07618 
## Number of obs: 82, groups:  subid, 41
## 
## Fixed effects:
##                         Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)             0.550156   0.017165 39.000000  32.050   <2e-16 ***
## group1                 -0.020211   0.017165 39.000000  -1.177   0.2462    
## mem_conditions1        -0.018688   0.008416 39.000000  -2.221   0.0323 *  
## group1:mem_conditions1 -0.004962   0.008416 39.000000  -0.590   0.5588    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 mm_cn1
## group1      -0.024              
## mem_cndtns1  0.000  0.000       
## grp1:mm_cn1  0.000  0.000 -0.024
# anova(fit)

RT: HC assoc hits by encoding strength

Calculate median/SDs:

## [1] ap110 ap158 ap151 ap156 ap173
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
## Source: local data frame [4 x 5]
## Groups: group [?]
## 
## # A tibble: 4 x 5
##          group  reps     mean       sd     n
##         <fctr> <int>    <dbl>    <dbl> <int>
## 1 control-fmri     2 36.42857 17.18887    21
## 2 control-fmri     4 50.85714 17.88655    21
## 3  stress-fmri     2 21.42857 10.37098    21
## 4  stress-fmri     4 33.23810 12.29595    21
##   X run trial   onset duration shockCond shockTrial  target      associate
## 1 0   1     1 12.0191  10.6661      safe          0  BANDIT       cemetery
## 2 1   1     2 22.7129   9.1242      safe          0  WALRUS           foil
## 3 2   1     3 31.8642   9.4224      safe          0  VIOLIN    throne_room
## 4 3   1     4 41.3132  11.3389      safe          0   MEDAL       hayfield
## 5 4   1     5 52.6786   9.7644      safe          0  MANURE         canyon
## 6 5   1     6 62.4701   9.1180      safe          0 SARDINE mountain_snowy
##      resp acc accSpec respRT subid        group remove anxious happy safe
## 1  indoor  SM  SMO_Hi 2.1094 ap100 control-fmri     NA       3     2    3
## 2    foil  CR      CR 1.7773 ap100 control-fmri     NA       3     2    3
## 3  indoor   H   HI_Hi 1.6804 ap100 control-fmri     NA       3     2    3
## 4 outdoor   H   HO_Hi 1.7268 ap100 control-fmri     NA       3     2    3
## 5 outdoor   H   HO_Hi 1.3734 ap100 control-fmri     NA       3     2    3
## 6 outdoor   H   HO_Hi 2.1476 ap100 control-fmri     NA       3     2    3
##   stressed life_stress sleep cond_orig    cond reps shock_and_post conf
## 1        3           4   4.5      TO_4 outdoor    4              0   Hi
## 2        3           4   4.5       F_0    foil    0              0    N
## 3        3           4   4.5      TI_2  indoor    2              0   Hi
## 4        3           4   4.5      TO_2 outdoor    2              0   Hi
## 5        3           4   4.5      TO_2 outdoor    2              0   Hi
## 6        3           4   4.5      TO_4 outdoor    4              0   Hi
##   onset_adj mem_conditions obj_conditions onset_code        rt_z
## 1    0.0191  sourcemiss_hi            old    itemhit -1.20388009
## 2   10.7129             CR            new         CR -0.12867526
## 3   19.8642      sourcehit            old  sourcehit -0.74601988
## 4   29.3132      sourcehit            old  sourcehit -0.67385952
## 5   40.6786      sourcehit            old  sourcehit -1.22346016
## 6   50.4701      sourcehit            old  sourcehit -0.01943975
##   mem_conditions_byrep onset_code_byrep
## 1      sourcemiss_hi-4        itemhit-4
## 2                 CR-0             CR-0
## 3          sourcehit-2      sourcehit-2
## 4          sourcehit-2      sourcehit-2
## 5          sourcehit-2      sourcehit-2
## 6          sourcehit-4      sourcehit-4
## [1] 7

Median RT

contrasts(d$group) = c(1,-1); contrasts(d$group)
##              [,1]
## control-fmri    1
## stress-fmri    -1
contrasts(d$reps) = c(1,-1); contrasts(d$reps)
##   [,1]
## 2    1
## 4   -1
fit = lmer(rt ~ group * reps + (1|subid), data=d, REML=TRUE) # not enough obs for RE
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt ~ group * reps + (1 | subid)
##    Data: d
## 
## REML criterion at convergence: 20.7
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.14369 -0.38865 -0.00463  0.40178  1.77725 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.08755  0.2959  
##  Residual             0.01901  0.1379  
## Number of obs: 84, groups:  subid, 42
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   2.21325    0.04807 40.00000  46.041  < 2e-16 ***
## group1       -0.01536    0.04807 40.00000  -0.320 0.750963    
## reps1         0.06079    0.01504 40.00000   4.041 0.000235 ***
## group1:reps1  0.01384    0.01504 40.00000   0.920 0.362942    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 reps1
## group1      0.000              
## reps1       0.000  0.000       
## group1:rps1 0.000  0.000  0.000
d %>% group_by(reps) %>% summarise(mean(rt), sd(rt), n())
## # A tibble: 2 x 4
##     reps `mean(rt)`  `sd(rt)` `n()`
##   <fctr>      <dbl>     <dbl> <int>
## 1      2   2.274038 0.3246587    42
## 2      4   2.152455 0.3215515    42

SD RT

fit = lmer(rt_sd ~ group * reps + (1|subid), data=d, REML=TRUE) # not enough obs for RE
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt_sd ~ group * reps + (1 | subid)
##    Data: d
## 
## REML criterion at convergence: -122.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.77428 -0.56544  0.04429  0.44400  1.94456 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.005719 0.07562 
##  Residual             0.005967 0.07724 
## Number of obs: 84, groups:  subid, 42
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)   0.550051   0.014394 40.000000  38.213   <2e-16 ***
## group1       -0.012048   0.014394 40.000000  -0.837    0.408    
## reps1         0.014083   0.008428 40.000000   1.671    0.103    
## group1:reps1  0.002854   0.008428 40.000000   0.339    0.737    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 reps1
## group1      0.000              
## reps1       0.000  0.000       
## group1:rps1 0.000  0.000  0.000
# anova(fit)

RT: HC assoc hit - by run type

# Determine subs to toss due to low trial counts
drt = dt %>%
  filter(mem_conditions %in% c("sourcehit")) %>%
  group_by(group, subid, shockCond) %>%
  summarise(n=n())%>%
  ungroup() %>%
  complete(nesting(group, subid), shockCond, fill=list(n=0))

sub_list = drt %>% filter(n < 6) %>% ungroup %>% pull(subid) %>% unique()
sub_list
## [1] ap158 ap151 ap156 ap173
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
# look at mean trial counts/cond/group
drt %>%
  filter(!subid %in% sub_list) %>% # need at least 6 trials/bin
  group_by(group, shockCond) %>%
  summarise(mean=mean(n), sd=sd(n), n=n())
## Source: local data frame [4 x 5]
## Groups: group [?]
## 
## # A tibble: 4 x 5
##          group shockCond     mean       sd     n
##         <fctr>    <fctr>    <dbl>    <dbl> <int>
## 1 control-fmri      safe 42.54545 18.17567    22
## 2 control-fmri    threat 41.68182 18.44009    22
## 3  stress-fmri      safe 28.09524 10.89452    21
## 4  stress-fmri    threat 26.57143 11.58262    21
# get medians/sds
head(dt)
##   X run trial   onset duration shockCond shockTrial  target      associate
## 1 0   1     1 12.0191  10.6661      safe          0  BANDIT       cemetery
## 2 1   1     2 22.7129   9.1242      safe          0  WALRUS           foil
## 3 2   1     3 31.8642   9.4224      safe          0  VIOLIN    throne_room
## 4 3   1     4 41.3132  11.3389      safe          0   MEDAL       hayfield
## 5 4   1     5 52.6786   9.7644      safe          0  MANURE         canyon
## 6 5   1     6 62.4701   9.1180      safe          0 SARDINE mountain_snowy
##      resp acc accSpec respRT subid        group remove anxious happy safe
## 1  indoor  SM  SMO_Hi 2.1094 ap100 control-fmri     NA       3     2    3
## 2    foil  CR      CR 1.7773 ap100 control-fmri     NA       3     2    3
## 3  indoor   H   HI_Hi 1.6804 ap100 control-fmri     NA       3     2    3
## 4 outdoor   H   HO_Hi 1.7268 ap100 control-fmri     NA       3     2    3
## 5 outdoor   H   HO_Hi 1.3734 ap100 control-fmri     NA       3     2    3
## 6 outdoor   H   HO_Hi 2.1476 ap100 control-fmri     NA       3     2    3
##   stressed life_stress sleep cond_orig    cond reps shock_and_post conf
## 1        3           4   4.5      TO_4 outdoor    4              0   Hi
## 2        3           4   4.5       F_0    foil    0              0    N
## 3        3           4   4.5      TI_2  indoor    2              0   Hi
## 4        3           4   4.5      TO_2 outdoor    2              0   Hi
## 5        3           4   4.5      TO_2 outdoor    2              0   Hi
## 6        3           4   4.5      TO_4 outdoor    4              0   Hi
##   onset_adj mem_conditions obj_conditions onset_code        rt_z
## 1    0.0191  sourcemiss_hi            old    itemhit -1.20388009
## 2   10.7129             CR            new         CR -0.12867526
## 3   19.8642      sourcehit            old  sourcehit -0.74601988
## 4   29.3132      sourcehit            old  sourcehit -0.67385952
## 5   40.6786      sourcehit            old  sourcehit -1.22346016
## 6   50.4701      sourcehit            old  sourcehit -0.01943975
##   mem_conditions_byrep onset_code_byrep
## 1      sourcemiss_hi-4        itemhit-4
## 2                 CR-0             CR-0
## 3          sourcehit-2      sourcehit-2
## 4          sourcehit-2      sourcehit-2
## 5          sourcehit-2      sourcehit-2
## 6          sourcehit-4      sourcehit-4
drt = dt %>%
  filter(mem_conditions %in% c("sourcehit"),
         !subid %in% sub_list) %>%
  group_by(group, subid, shockCond) %>%
  summarise(rt=median(respRT), rt_sd = sd(respRT), n=n()) %>%
  ungroup() %>%
  mutate(shockCond = factor(shockCond))
drt
## # A tibble: 86 x 6
##           group  subid shockCond      rt     rt_sd     n
##          <fctr> <fctr>    <fctr>   <dbl>     <dbl> <int>
##  1 control-fmri  ap100      safe 2.09785 0.5652564    46
##  2 control-fmri  ap100    threat 2.03720 0.7217674    43
##  3 control-fmri  ap101      safe 2.00345 0.5399894    54
##  4 control-fmri  ap101    threat 1.89870 0.5025196    51
##  5 control-fmri  ap102      safe 2.06535 0.5593426    34
##  6 control-fmri  ap102    threat 1.93060 0.5694347    34
##  7 control-fmri  ap103      safe 2.95525 0.6363623    56
##  8 control-fmri  ap103    threat 3.06230 0.6758489    57
##  9 control-fmri  ap104      safe 1.95380 0.5650548    75
## 10 control-fmri  ap104    threat 1.83455 0.5149647    72
## # ... with 76 more rows
min(drt$n)
## [1] 7
contrasts(drt$group) = c(1,-1); contrasts(drt$group)
##              [,1]
## control-fmri    1
## stress-fmri    -1
contrasts(drt$shockCond) = c(1,-1); contrasts(drt$shockCond)
##        [,1]
## safe      1
## threat   -1
bartlett.test(rt ~ shockCond, data=drt %>% filter(group == 'stress-fmri'))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  rt by shockCond
## Bartlett's K-squared = 0.033052, df = 1, p-value = 0.8557
t.test(rt ~ shockCond, data=drt %>% filter(group == 'stress-fmri'), 
       paired=TRUE, var.equal=TRUE)
## 
##  Paired t-test
## 
## data:  rt by shockCond
## t = 2.0394, df = 20, p-value = 0.05484
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.002008068  0.177922354
## sample estimates:
## mean of the differences 
##              0.08795714
drt %>% group_by(group, shockCond) %>% summarise(n())
## Source: local data frame [4 x 3]
## Groups: group [?]
## 
## # A tibble: 4 x 3
##          group shockCond `n()`
##         <fctr>    <fctr> <int>
## 1 control-fmri      safe    22
## 2 control-fmri    threat    22
## 3  stress-fmri      safe    21
## 4  stress-fmri    threat    21
bartlett.test(rt ~ group, data=drt %>% filter(shockCond == 'threat'))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  rt by group
## Bartlett's K-squared = 1.192, df = 1, p-value = 0.2749
t.test(rt ~ group, data=drt %>% filter(shockCond == 'threat'), 
       paired=FALSE, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  rt by group
## t = 0.2374, df = 41, p-value = 0.8135
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1783869  0.2259126
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                   2.198680                   2.174917
summary(lmer(rt ~ group * shockCond + (1  | subid), data=drt))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt ~ group * shockCond + (1 | subid)
##    Data: drt
## 
## REML criterion at convergence: 14.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.08156 -0.45837 -0.02917  0.28955  2.06907 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.09466  0.3077  
##  Residual             0.01549  0.1245  
## Number of obs: 86, groups:  subid, 43
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)        2.21627    0.04881 41.00000  45.401   <2e-16 ***
## group1            -0.00262    0.04881 41.00000  -0.054   0.9575    
## shockCond1         0.02948    0.01342 41.00000   2.196   0.0338 *  
## group1:shockCond1 -0.01450    0.01342 41.00000  -1.080   0.2863    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1
## group1      -0.023              
## shockCond1   0.000  0.000       
## grp1:shckC1  0.000  0.000 -0.023
bartlett.test(rt_sd ~ shockCond, data=drt %>% filter(group == 'stress-fmri'))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  rt_sd by shockCond
## Bartlett's K-squared = 0.071461, df = 1, p-value = 0.7892
t.test(rt_sd ~ shockCond, data=drt %>% filter(group == 'stress-fmri'), 
       paired=TRUE, var.equal=TRUE)
## 
##  Paired t-test
## 
## data:  rt_sd by shockCond
## t = 0.17199, df = 20, p-value = 0.8652
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.06549640  0.07726781
## sample estimates:
## mean of the differences 
##             0.005885704
bartlett.test(rt_sd ~ group, data=drt %>% filter(shockCond == 'threat'))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  rt_sd by group
## Bartlett's K-squared = 4.4922, df = 1, p-value = 0.03405
t.test(rt_sd ~ group, data=drt %>% filter(shockCond == 'threat'), 
       paired=FALSE, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  rt_sd by group
## t = -0.60418, df = 41, p-value = 0.5491
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.08703793  0.04695245
## sample estimates:
## mean in group control-fmri  mean in group stress-fmri 
##                  0.5371164                  0.5571591
summary(lmer(rt_sd ~ group * shockCond + (1  | subid), data=drt))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt_sd ~ group * shockCond + (1 | subid)
##    Data: drt
## 
## REML criterion at convergence: -108.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.16712 -0.51203  0.00414  0.53979  1.80289 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.003345 0.05784 
##  Residual             0.009685 0.09841 
## Number of obs: 86, groups:  subid, 43
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)        0.5491875  0.0138027 41.0000000  39.788   <2e-16 ***
## group1            -0.0109145  0.0138027 41.0000000  -0.791    0.434    
## shockCond1         0.0020498  0.0106150 41.0000000   0.193    0.848    
## group1:shockCond1 -0.0008931  0.0106150 41.0000000  -0.084    0.933    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1
## group1      -0.023              
## shockCond1   0.000  0.000       
## grp1:shckC1  0.000  0.000 -0.023

2) Trial-wise analyses

Note that all these analyses exclude the 2 participants with poor VTC localizer classification:

Localizer classification:

VTC F1 score

d = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_f1_localizer_group_scalewithinrun.csv')
str(d)
## 'data.frame':    132 obs. of  8 variables:
##  $ X        : int  0 2 4 6 8 10 12 14 16 18 ...
##  $ category : Factor w/ 3 levels "face","object",..: 1 2 3 1 2 3 1 2 3 1 ...
##  $ mask_name: Factor w/ 1 level "bilat-parahipp_fusi_inftemp": 1 1 1 1 1 1 1 1 1 1 ...
##  $ mean     : num  0.949 0.84 0.875 0.921 0.859 ...
##  $ sd       : num  0.0349 0.0127 0.0279 0.0325 0.02 ...
##  $ subid    : Factor w/ 44 levels "ap100","ap101",..: 1 1 1 2 2 2 3 3 3 4 ...
##  $ type     : Factor w/ 1 level "f1 score": 1 1 1 1 1 1 1 1 1 1 ...
##  $ group    : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
# mean +/- SD
d %>% 
  group_by(subid, category) %>%
  summarise(mean = mean(mean)) %>%
  group_by(category) %>% 
  summarise(sd=sd(mean), f1 = mean(mean), n=n())
## # A tibble: 3 x 4
##   category         sd        f1     n
##     <fctr>      <dbl>     <dbl> <int>
## 1     face 0.05242748 0.8864267    44
## 2   object 0.08163720 0.8155268    44
## 3    place 0.06588833 0.8663450    44
# how are individ subjs doing? look for outliers
d_avg = d %>% 
          group_by(subid, group) %>%
          summarise(f1 = mean(mean))
head(d_avg)
## Source: local data frame [6 x 3]
## Groups: subid [6]
## 
## # A tibble: 6 x 3
##    subid   group        f1
##   <fctr>  <fctr>     <dbl>
## 1  ap100 control 0.8882706
## 2  ap101 control 0.8928758
## 3  ap102 control 0.8817173
## 4  ap103 control 0.8463258
## 5  ap104 control 0.8143320
## 6  ap105 control 0.8602789
boxplot(d_avg$f1)

boxplot.stats(d_avg$f1)
## $stats
## [1] 0.7898834 0.8413915 0.8581023 0.8874281 0.9542282
## 
## $n
## [1] 44
## 
## $conf
## [1] 0.8471366 0.8690679
## 
## $out
## [1] 0.6087732 0.7650795
outlier_values <- boxplot.stats(d_avg$f1)$out

d_avg %>% filter(f1 %in% outlier_values)
## Source: local data frame [2 x 3]
## Groups: subid [2]
## 
## # A tibble: 2 x 3
##    subid  group        f1
##   <fctr> <fctr>     <dbl>
## 1  ap168 stress 0.6087732
## 2  ap174 stress 0.7650795
subids_rm = d_avg %>% filter(f1 %in% outlier_values) %>% collect %>% .[["subid"]]
subids_rm # ap168 ap174
## [1] ap168 ap174
## 44 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap174
dim(d)
## [1] 132   8
d = d %>% filter(!subid %in% subids_rm)
dim(d)
## [1] 126   8
ggplot(d %>% 
         group_by(subid, group, category) %>%
         summarise(f1 = mean(mean)), aes(x=category, y=f1, color=group)) +
  geom_boxplot()+
  geom_point(alpha=.7, size=3, position=position_jitterdodge()) +
  ylab('F1 score')+
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  xlab('') + ylim(.5, 1)

contrasts(d$group) = c(1,-1); contrasts(d$group)
##         [,1]
## control    1
## stress    -1
contrasts(d$category) = cbind(objVother=c(1,-2,1),
                              faceVplace=c(1,0,-1)); contrasts(d$category)
##        objVother faceVplace
## face           1          1
## object        -2          0
## place          1         -1
fit = lmer(mean ~ group*category + (1|subid), data=d, REML=TRUE)
anova(fit)
## Analysis of Variance Table of type III  with  Satterthwaite 
## approximation for degrees of freedom
##                  Sum Sq  Mean Sq NumDF  DenDF F.value   Pr(>F)    
## group          0.001310 0.001310     1 40.000  0.6345   0.4304    
## category       0.084162 0.042081     2 80.001 20.3812 7.02e-08 ***
## group:category 0.007467 0.003734     2 80.001  1.8083   0.1706    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: mean ~ group * category + (1 | subid)
##    Data: d
## 
## REML criterion at convergence: -348.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6125 -0.6483  0.1128  0.6217  1.7904 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  subid    (Intercept) 0.0005532 0.02352 
##  Residual             0.0020647 0.04544 
## Number of obs: 126, groups:  subid, 42
## 
## Fixed effects:
##                            Estimate Std. Error        df t value Pr(>|t|)
## (Intercept)                0.863949   0.005443 40.000000 158.729  < 2e-16
## group1                     0.004335   0.005443 40.000000   0.797   0.4304
## categoryobjVother          0.017879   0.002866 80.000000   6.239 1.97e-08
## categoryfaceVplace         0.006728   0.004963 80.000000   1.356   0.1791
## group1:categoryobjVother   0.005145   0.002866 80.000000   1.795   0.0764
## group1:categoryfaceVplace -0.003114   0.004963 80.000000  -0.627   0.5322
##                              
## (Intercept)               ***
## group1                       
## categoryobjVother         ***
## categoryfaceVplace           
## group1:categoryobjVother  .  
## group1:categoryfaceVplace    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##              (Intr) group1 ctgrybV ctgryfV grp1:ctgrybV
## group1       -0.048                                    
## ctgrybjVthr   0.000  0.000                             
## ctgryfcVplc   0.000  0.000  0.000                      
## grp1:ctgrybV  0.000  0.000 -0.048   0.000              
## grp1:ctgryfV  0.000  0.000  0.000  -0.048   0.000

Inferior parietal F1 score

d = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_f1_localizer_inferiorparietal_group_scalewithinrun.csv')
str(d)
## 'data.frame':    132 obs. of  8 variables:
##  $ X        : int  0 2 4 6 8 10 12 14 16 18 ...
##  $ category : Factor w/ 3 levels "face","object",..: 1 2 3 1 2 3 1 2 3 1 ...
##  $ mask_name: Factor w/ 1 level "lh-inferiorparietal": 1 1 1 1 1 1 1 1 1 1 ...
##  $ mean     : num  0.837 0.638 0.822 0.891 0.85 ...
##  $ sd       : num  0.00825 0.01871 0.00193 0.02976 0.03865 ...
##  $ subid    : Factor w/ 44 levels "ap100","ap101",..: 1 1 1 2 2 2 3 3 3 4 ...
##  $ type     : Factor w/ 1 level "f1 score": 1 1 1 1 1 1 1 1 1 1 ...
##  $ group    : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
# mean +/- SD
d %>% 
  group_by(subid, category) %>%
  summarise(mean = mean(mean)) %>%
  group_by(category) %>% 
  summarise(sd=sd(mean), f1 = mean(mean), n=n())
## # A tibble: 3 x 4
##   category         sd        f1     n
##     <fctr>      <dbl>     <dbl> <int>
## 1     face 0.07580574 0.7747272    44
## 2   object 0.10549956 0.7081117    44
## 3    place 0.06744105 0.8162107    44
# how are individ subjs doing? look for outliers
d_avg = d %>% 
          group_by(subid, group) %>%
          summarise(f1 = mean(mean))
head(d_avg)
## Source: local data frame [6 x 3]
## Groups: subid [6]
## 
## # A tibble: 6 x 3
##    subid   group        f1
##   <fctr>  <fctr>     <dbl>
## 1  ap100 control 0.7656174
## 2  ap101 control 0.8799442
## 3  ap102 control 0.8071681
## 4  ap103 control 0.6936104
## 5  ap104 control 0.7287970
## 6  ap105 control 0.7839734
boxplot(d_avg$f1)

boxplot.stats(d_avg$f1)
## $stats
## [1] 0.6618044 0.7327632 0.7570372 0.8029153 0.8985969
## 
## $n
## [1] 44
## 
## $conf
## [1] 0.7403274 0.7737471
## 
## $out
## [1] 0.5318235
outlier_values <- boxplot.stats(d_avg$f1)$out

d_avg %>% filter(f1 %in% outlier_values)
## Source: local data frame [1 x 3]
## Groups: subid [1]
## 
## # A tibble: 1 x 3
##    subid  group        f1
##   <fctr> <fctr>     <dbl>
## 1  ap168 stress 0.5318235
subids_rm = d_avg %>% filter(f1 %in% outlier_values) %>% collect %>% .[["subid"]]
subids_rm # ap168
## [1] ap168
## 44 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap174
dim(d)
## [1] 132   8
d = d %>% filter(!subid %in% subids_rm)
dim(d)
## [1] 129   8
ggplot(d %>% 
         group_by(subid, group, category) %>%
         summarise(f1 = mean(mean)), aes(x=category, y=f1, color=group)) +
  geom_boxplot()+
  geom_point(alpha=.7, size=3, position=position_jitterdodge()) +
  ylab('F1 score')+
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  xlab('') + ylim(.5, 1)

contrasts(d$group) = c(1,-1); contrasts(d$group)
##         [,1]
## control    1
## stress    -1
contrasts(d$category) = cbind(objVother=c(1,-2,1),
                              faceVplace=c(1,0,-1)); contrasts(d$category)
##        objVother faceVplace
## face           1          1
## object        -2          0
## place          1         -1
fit = lmer(mean ~ group*category + (1|subid), data=d, REML=TRUE)
anova(fit)
## Analysis of Variance Table of type III  with  Satterthwaite 
## approximation for degrees of freedom
##                  Sum Sq  Mean Sq NumDF DenDF F.value    Pr(>F)    
## group          0.009481 0.009481     1    41  2.3455    0.1333    
## category       0.227530 0.113765     2    82 28.1446 4.943e-10 ***
## group:category 0.001778 0.000889     2    82  0.2200    0.8030    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: mean ~ group * category + (1 | subid)
##    Data: d
## 
## REML criterion at convergence: -266.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6684 -0.6006  0.1029  0.6387  1.9203 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.001602 0.04003 
##  Residual             0.004042 0.06358 
## Number of obs: 129, groups:  subid, 43
## 
## Fixed effects:
##                            Estimate Std. Error        df t value Pr(>|t|)
## (Intercept)                0.771509   0.008285 41.000000  93.126  < 2e-16
## group1                     0.012688   0.008285 41.000000   1.532   0.1333
## categoryobjVother          0.027432   0.003959 82.000000   6.929 8.82e-10
## categoryfaceVplace        -0.019737   0.006858 82.000000  -2.878   0.0051
## group1:categoryobjVother   0.001373   0.003959 82.000000   0.347   0.7296
## group1:categoryfaceVplace  0.003877   0.006858 82.000000   0.565   0.5734
##                              
## (Intercept)               ***
## group1                       
## categoryobjVother         ***
## categoryfaceVplace        ** 
## group1:categoryobjVother     
## group1:categoryfaceVplace    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##              (Intr) group1 ctgrybV ctgryfV grp1:ctgrybV
## group1       -0.023                                    
## ctgrybjVthr   0.000  0.000                             
## ctgryfcVplc   0.000  0.000  0.000                      
## grp1:ctgrybV  0.000  0.000 -0.023   0.000              
## grp1:ctgryfV  0.000  0.000  0.000  -0.023   0.000

Load in data

d = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_place_byreps_avg_46810_filtartloc_scalewithinrun.csv')

subids_rm = c('ap168', 'ap174') # bad VTC localizer classification

# filter d to just good subjs, and only OLD items
d = d %>%
  filter(!subid %in% subids_rm) %>%
  filter(cond %in% c('sourcemiss_hi', 'sourcehit', 'M', 'itemhit_lo')) %>%
  mutate(pcorr = factor(ifelse(cond == "sourcehit", 1, 0)),
         vtc_logit = avg_logit)

dt %>% filter(shock_and_post == 2) # one subj w/consecutive shocks - trial needs to be removed (though mem_condition == 'nuisance')
##      X run trial    onset duration shockCond shockTrial target associate
## 1 6677   5    13 141.3117  11.5306    threat          1   WHIP     ocean
##      resp acc accSpec respRT subid       group remove anxious happy safe
## 1 outdoor   H   HO_Hi 0.1927 ap160 stress-fmri     NA       4     3    6
##   stressed life_stress sleep cond_orig    cond reps shock_and_post conf
## 1        5           3   4.5      TO_4 outdoor    4              2   Hi
##   onset_adj mem_conditions obj_conditions onset_code      rt_z
## 1  129.3117       nuisance       nuisance   nuisance -3.136573
##   mem_conditions_byrep onset_code_byrep
## 1           nuisance-4       nuisance-4
# Merge w/other behavioral info
d = dt %>%
  mutate(onset=onset_adj, img_type=cond) %>% 
  dplyr::select(-group, -reps, -cond) %>%
  right_join(d, by=c('subid', 'run', 'onset')) %>%
  mutate(subid = factor(subid), imgType = factor(img_type))
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
dim(d)
## [1] 6624   50
d = d %>% filter(shock_and_post == 0)
dim(d)
## [1] 6623   50
# Read in hipp BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-hippocampus.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-hippocampus.csv')
# dim(roi_lh); dim(roi_rh)

# Take timepoints of interest for old trials, and collapse across hemispheres
roi_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(hipp_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# Read in hipp tail BOLD (as potential secondary analysis)
roi_tail_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-hippocampus-tail.csv')
roi_tail_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-hippocampus-tail.csv')

# Take timepoints of interest for old trials, and collapse across hemispheres
roi_tail_f = bind_rows("lh" = roi_tail_lh, "rh" = roi_tail_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(hipp_tail_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# Read in angular BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-DefaultA_IPL.csv')
angular_lh_f = roi_lh %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, run, onset) %>%
  summarise(angular_lh_sig = mean_(mean_activity)) %>% ungroup()

# Read in RSP BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-DefaultC_Rsp.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-DefaultC_Rsp.csv')

# Take timepoints of interest for old trials, and collapse across hemispheres
rsp_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(rsp_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# Read in CCN BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-frontoparietal.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-frontoparietal.csv')
# dim(roi_lh); dim(roi_rh)

# Take timepoints of interest for old trials, and collapse across hemispheres
CCN_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(CCN_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# also, just for LH
CCN_lh_f = roi_lh %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, run, onset) %>%
  summarise(CCN_lh_sig = mean_(mean_activity)) %>% ungroup()

# Read in DAN BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-dorsalattn.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-dorsalattn.csv')
# dim(roi_lh); dim(roi_rh)

# Take timepoints of interest for old trials, and collapse across hemispheres
DAN_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(DAN_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# also, just for LH
DAN_lh_f = roi_lh %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, run, onset) %>%
  summarise(DAN_lh_sig = mean_(mean_activity)) %>% ungroup()

# Other reinstatement
d_infpar = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_inferiorparietal_place_byreps_avg_46810_filtartloc_scalewithinrun.csv') %>%
  filter(!subid %in% subids_rm) %>%
  filter(cond %in% c('sourcemiss_hi', 'sourcehit', 'M', 'itemhit_lo')) %>%
  mutate(ang_logit = avg_logit) %>%
  dplyr::select(subid, run, onset, ang_logit)

d_hipp = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_bilat-hippocampus_place_byreps_avg_46810_filtartloc_scalewithinrun.csv') %>%
  filter(!subid %in% subids_rm) %>%
  filter(cond %in% c('sourcemiss_hi', 'sourcehit', 'M', 'itemhit_lo')) %>%
  mutate(pcorr = factor(ifelse(cond == "sourcehit", 1, 0)),
         hipp_logit = avg_logit) %>%
  dplyr::select(subid, run, onset, hipp_logit)

# to see if need phc (maybe includes "general memory" response?)
d_vtc_nophc = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_bilat-fusi_inftemp_place_byreps_avg_46810_filtartloc_scalewithinrun.csv') %>%
  filter(!subid %in% subids_rm) %>%
  filter(cond %in% c('sourcemiss_hi', 'sourcehit', 'M', 'itemhit_lo')) %>%
  mutate(pcorr = factor(ifelse(cond == "sourcehit", 1, 0)),
         vtc_nophc_logit = avg_logit) %>%
  dplyr::select(subid, run, onset, vtc_nophc_logit)

# Merge w/VTC classifier evidence
dm = d %>%
  left_join(roi_f, by=c('subid', 'run', 'onset')) %>%
  left_join(roi_tail_f, by=c('subid', 'run', 'onset')) %>%
  left_join(DAN_f, by=c('subid', 'run', 'onset')) %>%
  left_join(CCN_f, by=c('subid', 'run', 'onset')) %>%
  left_join(rsp_f, by=c('subid', 'run', 'onset')) %>%
  left_join(angular_lh_f, by=c('subid', 'run', 'onset')) %>%
  left_join(DAN_lh_f, by=c('subid', 'run', 'onset')) %>%
  left_join(CCN_lh_f, by=c('subid', 'run', 'onset')) %>%
  left_join(d_infpar, by=c('subid', 'run', 'onset')) %>%
  left_join(d_hipp, by=c('subid', 'run', 'onset')) %>%
  left_join(d_vtc_nophc, by=c('subid', 'run', 'onset')) %>%
  group_by(subid) %>%
  mutate(ang_logit_z = zscore(ang_logit),
         vtc_logit_z = zscore(vtc_logit),
         hipp_logit_z = zscore(hipp_logit),
         CCN_sig_z = zscore(CCN_sig),
         rsp_sig_z = zscore(rsp_sig),
         DAN_sig_z = zscore(DAN_sig),
         angular_lh_sig_z = zscore(angular_lh_sig),
         CCN_lh_sig_z = zscore(CCN_lh_sig),
         DAN_lh_sig_z = zscore(DAN_lh_sig),
         hipp_sig_z = zscore(hipp_sig),
         hipp_tail_sig_z = zscore(hipp_tail_sig),
         reps = factor(reps),
         hipp_quintile = ntile(hipp_sig, 5),
         rsp_quintile = ntile(rsp_sig, 5),
         CCN_quintile = ntile(CCN_sig, 5),
         DAN_quintile = ntile(DAN_sig, 5),
         angular_lh_sig_quintile = ntile(angular_lh_sig, 5),
         CCN_lh_quintile = ntile(CCN_lh_sig, 5),
         DAN_lh_quintile = ntile(DAN_lh_sig, 5),
         hipp_tail_quintile = ntile(hipp_tail_sig, 5),
         vtc_quintile = ntile(vtc_logit, 5),
         hipp_logit_quintile = ntile(hipp_logit, 5),
         ang_quintile = ntile(ang_logit, 5)) %>%
  ungroup() %>%
  mutate(subid = factor(subid),
         cond = factor(cond),
         condition = factor(condition))
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector
dim(dm) #just hipp: 6623  
## [1] 6623   83
with(dm, table(subid, reps))
##        reps
## subid    2  4
##   ap100 76 78
##   ap101 83 82
##   ap102 80 79
##   ap103 83 79
##   ap104 82 83
##   ap105 81 81
##   ap107 79 82
##   ap108 72 74
##   ap109 81 77
##   ap110 82 81
##   ap111 82 84
##   ap113 83 83
##   ap114 81 81
##   ap115 78 82
##   ap116 80 82
##   ap117 84 80
##   ap118 83 81
##   ap119 80 81
##   ap120 79 76
##   ap121 84 81
##   ap122 84 82
##   ap150 77 78
##   ap152 73 78
##   ap153 77 75
##   ap154 67 78
##   ap155 69 66
##   ap157 77 79
##   ap158 84 83
##   ap159 81 81
##   ap160 66 64
##   ap161 81 79
##   ap162 75 80
##   ap163 83 78
##   ap164 79 79
##   ap165 75 81
##   ap166 79 79
##   ap167 76 77
##   ap169 77 79
##   ap170 81 81
##   ap171 81 81
##   ap172 80 76
##   ap173 73 74
str(dm)
## Classes 'tbl_df', 'tbl' and 'data.frame':    6623 obs. of  83 variables:
##  $ X.x                    : int  0 2 3 4 5 7 8 11 14 15 ...
##  $ run                    : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ trial                  : int  1 3 4 5 6 8 9 12 15 16 ...
##  $ onset                  : num  0.0191 19.8642 29.3132 40.6786 50.4701 ...
##  $ duration               : num  10.67 9.42 11.34 9.76 9.12 ...
##  $ shockCond              : Factor w/ 2 levels "safe","threat": 1 1 1 1 1 1 1 1 1 1 ...
##  $ shockTrial             : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ target                 : Factor w/ 252 levels "ACCORDIAN","ACROBAT",..: 15 238 116 114 183 224 87 102 192 191 ...
##  $ associate              : Factor w/ 241 levels "\002\002","\002",..: 68 237 126 61 175 233 53 118 173 84 ...
##  $ resp                   : Factor w/ 4 levels "foil","indoor",..: 2 2 4 4 4 1 1 1 4 2 ...
##  $ acc                    : Factor w/ 6 levels "CR","FA","H",..: 6 3 3 3 3 4 4 4 3 3 ...
##  $ accSpec                : Factor w/ 15 levels "CR","FAI_Hi",..: 14 6 8 8 8 10 10 10 8 6 ...
##  $ respRT                 : num  2.11 1.68 1.73 1.37 2.15 ...
##  $ subid                  : Factor w/ 42 levels "ap100","ap101",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ remove                 : logi  NA NA NA NA NA NA ...
##  $ anxious                : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ happy                  : int  2 2 2 2 2 2 2 2 2 2 ...
##  $ safe                   : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ stressed               : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ life_stress            : int  4 4 4 4 4 4 4 4 4 4 ...
##  $ sleep                  : num  4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 ...
##  $ cond_orig              : Factor w/ 5 levels "F_0","TI_2","TI_4",..: 5 2 4 4 5 3 2 4 5 2 ...
##  $ shock_and_post         : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ conf                   : Factor w/ 3 levels "Hi","Lo","N": 1 1 1 1 1 3 3 3 1 1 ...
##  $ onset_adj              : num  0.0191 19.8642 29.3132 40.6786 50.4701 ...
##  $ mem_conditions         : Factor w/ 7 levels "CR","FA","itemhit_lo",..: 7 6 6 6 6 4 4 4 6 6 ...
##  $ obj_conditions         : Factor w/ 3 levels "new","nuisance",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ onset_code             : Factor w/ 6 levels "CR","FA","itemhit",..: 3 6 6 6 6 4 4 4 6 6 ...
##  $ rt_z                   : num  -1.2039 -0.746 -0.6739 -1.2235 -0.0194 ...
##  $ mem_conditions_byrep   : Factor w/ 13 levels "CR-0","FA-0",..: 13 10 10 10 11 6 5 5 11 10 ...
##  $ onset_code_byrep       : Factor w/ 11 levels "CR-0","FA-0",..: 4 10 10 10 11 6 5 5 11 10 ...
##  $ img_type               : Factor w/ 3 levels "foil","indoor",..: 3 2 3 3 3 2 2 3 3 2 ...
##  $ X.y                    : int  2 8 11 14 17 23 26 35 44 47 ...
##  $ index                  : int  2 8 11 14 17 23 26 35 44 47 ...
##  $ group                  : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ condition              : Factor w/ 8 levels "itemhit_lo-2",..: 8 5 5 5 6 4 3 3 6 5 ...
##  $ category               : Factor w/ 1 level "place": 1 1 1 1 1 1 1 1 1 1 ...
##  $ X0                     : num  -6.635 -9.265 6.804 8.431 0.203 ...
##  $ X2                     : num  -6.32 -4.39 7.22 3.92 -3.54 ...
##  $ X4                     : num  -1.49 5.79 4.22 1.8 -2.75 ...
##  $ X6                     : num  2.59 5.69 -3.03 3.7 3.74 ...
##  $ X8                     : num  -1.03 8.65 -1.68 -1.28 -2.28 ...
##  $ X10                    : num  -0.642 6.486 8.468 -0.23 -9.405 ...
##  $ X12                    : num  -1.1 6.64 11.49 -3.55 -5.64 ...
##  $ avg_logit              : num  -0.145 6.655 1.996 0.998 -2.673 ...
##  $ cond                   : Factor w/ 4 levels "itemhit_lo","M",..: 4 3 3 3 3 2 2 2 3 3 ...
##  $ reps                   : Factor w/ 2 levels "2","4": 2 1 1 1 2 2 1 1 2 1 ...
##  $ pcorr                  : Factor w/ 2 levels "0","1": 1 2 2 2 2 1 1 1 2 2 ...
##  $ vtc_logit              : num  -0.145 6.655 1.996 0.998 -2.673 ...
##  $ imgType                : Factor w/ 2 levels "indoor","outdoor": 2 1 2 2 2 1 1 2 2 1 ...
##  $ hipp_sig               : num  0.2754 0.4613 -0.1955 -0.0154 -0.14 ...
##  $ hipp_tail_sig          : num  0.11449 0.49252 -0.00556 -0.06895 -0.13196 ...
##  $ DAN_sig                : num  0.175 0.658 0.225 -0.262 -0.395 ...
##  $ CCN_sig                : num  0.367 0.4107 0.0192 -0.1273 -0.2068 ...
##  $ rsp_sig                : num  0.3053 1.5956 -0.0991 -0.19 -0.5123 ...
##  $ angular_lh_sig         : num  0.20058 0.85916 -0.09532 0.00574 -0.04293 ...
##  $ DAN_lh_sig             : num  0.212 0.585 0.183 -0.233 -0.383 ...
##  $ CCN_lh_sig             : num  0.3687 0.2566 0.1633 -0.1271 -0.0121 ...
##  $ ang_logit              : num  -2.066 5.935 0.249 -3.792 -6.49 ...
##  $ hipp_logit             : num  -2.553 1.418 -1.783 -2.571 -0.555 ...
##  $ vtc_nophc_logit        : num  0.249 6.553 1.733 0.751 -3.801 ...
##  $ ang_logit_z            : num  -0.474 1.931 0.222 -0.993 -1.804 ...
##  $ vtc_logit_z            : num  -0.148 1.895 0.495 0.195 -0.907 ...
##  $ hipp_logit_z           : num  -0.491 1.406 -0.123 -0.499 0.464 ...
##  $ CCN_sig_z              : num  0.6436 0.7336 -0.0722 -0.3738 -0.5374 ...
##  $ rsp_sig_z              : num  0.209 2.071 -0.375 -0.506 -0.971 ...
##  $ DAN_sig_z              : num  0.391 1.606 0.516 -0.711 -1.046 ...
##  $ angular_lh_sig_z       : num  0.177 1.513 -0.423 -0.218 -0.317 ...
##  $ CCN_lh_sig_z           : num  0.537 0.31 0.121 -0.468 -0.235 ...
##  $ DAN_lh_sig_z           : num  0.437 1.389 0.363 -0.7 -1.082 ...
##  $ hipp_sig_z             : num  0.537 0.967 -0.552 -0.135 -0.424 ...
##  $ hipp_tail_sig_z        : num  0.167 1.146 -0.143 -0.307 -0.47 ...
##  $ hipp_quintile          : int  4 5 2 3 2 1 4 1 3 4 ...
##  $ rsp_quintile           : int  3 5 2 2 1 1 4 1 3 3 ...
##  $ CCN_quintile           : int  4 4 3 2 2 1 5 1 3 3 ...
##  $ DAN_quintile           : int  4 5 4 2 1 1 4 1 2 4 ...
##  $ angular_lh_sig_quintile: int  3 5 2 3 2 1 2 1 4 4 ...
##  $ CCN_lh_quintile        : int  4 3 3 2 3 1 5 1 4 3 ...
##  $ DAN_lh_quintile        : int  4 5 4 2 1 1 4 1 3 4 ...
##  $ hipp_tail_quintile     : int  3 5 3 2 2 1 4 1 3 5 ...
##  $ vtc_quintile           : int  3 5 4 3 1 2 2 1 5 4 ...
##  $ hipp_logit_quintile    : int  2 5 3 2 4 2 5 3 1 3 ...
##  $ ang_quintile           : int  2 5 4 1 1 1 4 2 4 5 ...
# set up contrasts
contrasts(dm$pcorr) = c(-1,1); contrasts(dm$pcorr)
##   [,1]
## 0   -1
## 1    1
contrasts(dm$reps) = c(-1,1); contrasts(dm$reps)
##   [,1]
## 2   -1
## 4    1
contrasts(dm$group) = c(1,-1); contrasts(dm$group)
##         [,1]
## control    1
## stress    -1
contrasts(dm$shockCond) = c(1,-1); contrasts(dm$shockCond)
##        [,1]
## safe      1
## threat   -1

Trial-wise analysis counts/group:

dm %>% group_by(subid, group) %>% summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    20
dm %>% mutate(avg = (X4+X6+X8+X10)/4) %>%
  filter(round(vtc_logit,3) != round(avg,3)) %>%
  dplyr::select(vtc_logit, avg)
## # A tibble: 0 x 2
## # ... with 2 variables: vtc_logit <dbl>, avg <dbl>

Trial counts/cond

# all subjs must have at least 6 trials of each type for sh vs cr analyses
dt %>% filter(mem_conditions %in% c('sourcehit', 'CR'))%>% 
  mutate(mem_conditions = factor(mem_conditions)) %>%
  group_by(subid, mem_conditions) %>% summarise(n()) %>% 
  ungroup() %>%
  complete(nesting(subid), mem_conditions, fill = list(`n()` = 0)) %>%
  filter(`n()` < 6)
## # A tibble: 2 x 3
##    subid mem_conditions `n()`
##   <fctr>         <fctr> <dbl>
## 1  ap151      sourcehit     3
## 2  ap156      sourcehit     5
# must exclude: ap151, ap156

# need at least 2 runs with BOTH 1 SH and 1 CR
dt %>% filter(mem_conditions %in% c('sourcehit', 'CR'))%>% 
  mutate(mem_conditions = factor(mem_conditions)) %>%
  group_by(subid, run, mem_conditions) %>% 
  summarise(count = n()) %>%
  ungroup() %>%
  complete(nesting(subid, run), mem_conditions, fill = list(count = 0)) %>%
  spread(key=mem_conditions, value=count, fill = 0) %>%
  filter(CR == 0 | sourcehit == 0)
## # A tibble: 17 x 4
##     subid   run    CR sourcehit
##    <fctr> <int> <dbl>     <dbl>
##  1  ap110     6    12         0
##  2  ap121     4     0        10
##  3  ap121     5     0         9
##  4  ap121     6     0         5
##  5  ap151     2     8         0
##  6  ap151     3     6         0
##  7  ap151     5     4         0
##  8  ap151     6     5         0
##  9  ap156     2     6         0
## 10  ap156     4     8         0
## 11  ap156     6     1         0
## 12  ap158     6     9         0
## 13  ap164     5     0        15
## 14  ap172     3     4         0
## 15  ap173     4     8         0
## 16  ap173     5     6         0
## 17  ap173     6    12         0
# remaining subjs have a min of 3 runs with both

# this leaves this many subjs/group for analyses collapsing across shockCond:
dt %>% filter(!subid %in% c('ap151', 'ap156')) %>% 
  group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##          group `n()`
##         <fctr> <int>
## 1 control-fmri    23
## 2  stress-fmri    22
# 22 controls/22 stress
# minus 1 control for too much movement! (T1 is even blurry...)

# Now, for shockCond analyses:

# all subjs must have at least 6 trials of each type
dt %>% filter(mem_conditions %in% c('sourcehit', 'CR'))%>% 
  mutate(mem_conditions = factor(mem_conditions),
         shockCond = factor(shockCond)) %>%
  group_by(subid, group, mem_conditions, shockCond) %>% summarise(n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), mem_conditions, shockCond, fill = list(`n()` = 0)) %>%
filter(`n()` < 6)
## # A tibble: 8 x 5
##    subid        group mem_conditions shockCond `n()`
##   <fctr>       <fctr>         <fctr>    <fctr> <dbl>
## 1  ap121 control-fmri             CR    threat     1
## 2  ap151  stress-fmri      sourcehit      safe     2
## 3  ap151  stress-fmri      sourcehit    threat     1
## 4  ap156  stress-fmri      sourcehit      safe     0
## 5  ap156  stress-fmri      sourcehit    threat     5
## 6  ap158 control-fmri      sourcehit      safe     5
## 7  ap164  stress-fmri             CR      safe     5
## 8  ap173  stress-fmri      sourcehit    threat     1
# ap121 (control): 1 threat CR
# ap158 (control): 5 safe SH
# ap164 (stress) 5 safe CR
# ap173 (stress) 1 threat SH

# 6 runs for everyone by ap155 (had to leave early on day1)
dt %>% group_by(subid, run) %>% summarise(n()) %>% group_by(subid) %>% summarise(n())
## # A tibble: 47 x 2
##     subid `n()`
##    <fctr> <int>
##  1  ap100     6
##  2  ap101     6
##  3  ap102     6
##  4  ap103     6
##  5  ap104     6
##  6  ap105     6
##  7  ap106     6
##  8  ap107     6
##  9  ap108     6
## 10  ap109     6
## # ... with 37 more rows
(47 - 6) * 6 * 2 - 2 #490 rows
## [1] 490
# need at least 2 runs with BOTH 1 SH and 1 CR
dt %>% filter(!subid %in% c('ap151', 'ap156', 'ap121', 'ap158', 'ap164', 'ap173')) %>%
  filter(mem_conditions %in% c('sourcehit', 'CR'))%>% 
  mutate(mem_conditions = factor(mem_conditions)) %>%
  group_by(subid, group, run, mem_conditions, shockCond) %>% 
  summarise(count = n()) %>%
  ungroup() %>%
  complete(nesting(subid, group, run, shockCond), mem_conditions, fill = list(count = 0)) %>%
  filter(count == 0)
## # A tibble: 2 x 6
##    subid        group   run shockCond mem_conditions count
##   <fctr>       <fctr> <int>    <fctr>         <fctr> <dbl>
## 1  ap110 control-fmri     6      safe      sourcehit     0
## 2  ap172  stress-fmri     3    threat      sourcehit     0
#2 subjs are missing 1 cond for 1 run; that means they have 2 good runs (at least 1 trial/condition) for each shockC type

# dt %>% filter(subid %in% c('ap110', 'ap172')) %>%
#   filter(mem_conditions %in% c('sourcehit', 'CR'))%>% 
#   mutate(mem_conditions = factor(mem_conditions)) %>%
#   group_by(subid, group, run, mem_conditions, shockCond) %>% 
#   summarise(count = n()) %>%
#   ungroup() %>%
#   complete(nesting(subid, group, run, shockCond), mem_conditions, fill = list(count = 0))

Are hipp quintiles matched across groups?

No significant differences in hipp BOLD between groups at each quintile:

dm %>% filter(hipp_quintile == 4) %>% group_by(group, subid) %>% summarise(n()) %>% 
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    20
summary(lmer(hipp_sig ~ group + (1|subid), data=dm %>% filter(hipp_quintile == 1)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: hipp_sig ~ group + (1 | subid)
##    Data: dm %>% filter(hipp_quintile == 1)
## 
## REML criterion at convergence: -634.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -7.4097 -0.3535  0.2376  0.6225  1.8068 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.01390  0.1179  
##  Residual             0.03333  0.1826  
## Number of obs: 1343, groups:  subid, 42
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept) -0.361779   0.018886 39.880000 -19.156   <2e-16 ***
## group1      -0.005891   0.018886 39.880000  -0.312    0.757    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.049
summary(lmer(hipp_sig ~ group + (1|subid), data=dm %>% filter(hipp_quintile == 2)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: hipp_sig ~ group + (1 | subid)
##    Data: dm %>% filter(hipp_quintile == 2)
## 
## REML criterion at convergence: -3960.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -3.10945 -0.67267  0.04051  0.70505  2.51204 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.001973 0.04441 
##  Residual             0.002610 0.05109 
## Number of obs: 1321, groups:  subid, 42
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept) -0.099264   0.007005 39.810000 -14.171   <2e-16 ***
## group1       0.002773   0.007005 39.810000   0.396    0.694    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.049
summary(lmer(hipp_sig ~ group + (1|subid), data=dm %>% filter(hipp_quintile == 3)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: hipp_sig ~ group + (1 | subid)
##    Data: dm %>% filter(hipp_quintile == 3)
## 
## REML criterion at convergence: -4646.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.1710 -0.7195  0.0329  0.7330  2.8131 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.001212 0.03481 
##  Residual             0.001571 0.03964 
## Number of obs: 1326, groups:  subid, 42
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  4.385e-02  5.488e-03  3.990e+01   7.991 8.27e-10 ***
## group1      -1.282e-05  5.488e-03  3.990e+01  -0.002    0.998    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.049
summary(lmer(hipp_sig ~ group + (1|subid), data=dm %>% filter(hipp_quintile == 4)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: hipp_sig ~ group + (1 | subid)
##    Data: dm %>% filter(hipp_quintile == 4)
## 
## REML criterion at convergence: -4146.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.70952 -0.72393 -0.03588  0.69258  3.13217 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.003880 0.06229 
##  Residual             0.002211 0.04702 
## Number of obs: 1321, groups:  subid, 42
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)  0.179235   0.009709 40.000000  18.460   <2e-16 ***
## group1      -0.003666   0.009709 40.000000  -0.378    0.708    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.048
summary(lmer(hipp_sig ~ group + (1|subid), data=dm %>% filter(hipp_quintile == 5)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: hipp_sig ~ group + (1 | subid)
##    Data: dm %>% filter(hipp_quintile == 5)
## 
## REML criterion at convergence: -1285.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.9834 -0.6897 -0.2188  0.4620  5.6170 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.01304  0.1142  
##  Residual             0.01976  0.1406  
## Number of obs: 1312, groups:  subid, 42
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)  0.411686   0.018064 39.980000  22.790   <2e-16 ***
## group1      -0.005993   0.018064 39.980000  -0.332    0.742    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.049

Are VTC quintiles matched across groups?

vtc logit is greater for controls at quintiles 3 and 4

head(dm)
## # A tibble: 6 x 83
##     X.x   run trial   onset duration shockCond shockTrial  target
##   <int> <dbl> <int>   <dbl>    <dbl>    <fctr>      <int>  <fctr>
## 1     0     1     1  0.0191  10.6661      safe          0  BANDIT
## 2     2     1     3 19.8642   9.4224      safe          0  VIOLIN
## 3     3     1     4 29.3132  11.3389      safe          0   MEDAL
## 4     4     1     5 40.6786   9.7644      safe          0  MANURE
## 5     5     1     6 50.4701   9.1180      safe          0 SARDINE
## 6     7     1     8 69.7414   9.9338      safe          0 TOBACCO
## # ... with 75 more variables: associate <fctr>, resp <fctr>, acc <fctr>,
## #   accSpec <fctr>, respRT <dbl>, subid <fctr>, remove <lgl>,
## #   anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>
summary(lmer(vtc_logit ~ group + (1|subid), data=dm %>% filter(vtc_quintile == 1)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ group + (1 | subid)
##    Data: dm %>% filter(vtc_quintile == 1)
## 
## REML criterion at convergence: 4685.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.2234 -0.4557  0.2496  0.7076  1.6110 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.4035   0.6352  
##  Residual             1.7907   1.3382  
## Number of obs: 1343, groups:  subid, 42
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)  -3.5467     0.1047 39.9600 -33.860   <2e-16 ***
## group1        0.1683     0.1047 39.9600   1.607    0.116    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.051
summary(lmer(vtc_logit ~ group + (1|subid), data=dm %>% filter(vtc_quintile == 2)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ group + (1 | subid)
##    Data: dm %>% filter(vtc_quintile == 2)
## 
## REML criterion at convergence: 1992.5
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.89570 -0.82235  0.01603  0.80407  2.38116 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.2003   0.4475  
##  Residual             0.2372   0.4871  
## Number of obs: 1321, groups:  subid, 42
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept) -1.16254    0.07042 39.95000 -16.508   <2e-16 ***
## group1       0.11115    0.07042 39.95000   1.578    0.122    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.049
summary(lmer(vtc_logit ~ group + (1|subid), data=dm %>% filter(vtc_quintile == 3)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ group + (1 | subid)
##    Data: dm %>% filter(vtc_quintile == 3)
## 
## REML criterion at convergence: 1418.3
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.25324 -0.77162  0.00782  0.78348  2.76927 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.1678   0.4097  
##  Residual             0.1517   0.3895  
## Number of obs: 1326, groups:  subid, 42
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  0.23431    0.06419 40.02000   3.650  0.00075 ***
## group1       0.13957    0.06419 40.02000   2.174  0.03565 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.048
summary(lmer(vtc_logit ~ group + (1|subid), data=dm %>% filter(vtc_quintile == 4)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ group + (1 | subid)
##    Data: dm %>% filter(vtc_quintile == 4)
## 
## REML criterion at convergence: 2170.3
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.56360 -0.74246 -0.07781  0.74215  2.91486 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.2388   0.4887  
##  Residual             0.2711   0.5207  
## Number of obs: 1321, groups:  subid, 42
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  1.67129    0.07685 40.04000  21.748   <2e-16 ***
## group1       0.17842    0.07685 40.04000   2.322   0.0254 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.049
summary(lmer(vtc_logit ~ group + (1|subid), data=dm %>% filter(vtc_quintile == 5)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ group + (1 | subid)
##    Data: dm %>% filter(vtc_quintile == 5)
## 
## REML criterion at convergence: 4829.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.5571 -0.7213 -0.2643  0.4988  4.9278 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.6685   0.8176  
##  Residual             2.1498   1.4662  
## Number of obs: 1312, groups:  subid, 42
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)   4.2302     0.1327 40.0600  31.884   <2e-16 ***
## group1        0.1980     0.1327 40.0600   1.492    0.143    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.050

VTC Mediation: Indirect effect of hipp -> VTC -> pcorr

Template borrowed from Alan Gordon (https://github.com/amgordon/Gordon_CerCor_2014)

Overall effect of hipp -> pcorr

mean(dm$hipp_sig_z)
## [1] -3.41811e-18
sd(dm$hipp_sig_z)
## [1] 0.9968995
mean(dm$vtc_logit_z)
## [1] 5.855437e-19
sd(dm$vtc_logit_z)
## [1] 0.9968995
# standardize continuous vars
dCleanStandardized = dm
dCleanStandardized$rGenHipp<-scale(dCleanStandardized$hipp_sig_z)
dCleanStandardized$ERActUnsigned<-scale(dCleanStandardized$vtc_logit_z)
dCleanStandardized$ERActUnsigned_infpar<-scale(dCleanStandardized$ang_logit_z)
dCleanStandardized$rGenANG<-scale(dCleanStandardized$angular_lh_sig_z)
dCleanStandardized$rGenRSP<-scale(dCleanStandardized$rsp_sig_z)


# overall effect
deq.0<-glmer(pcorr ~ group*(rGenHipp) + reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial")
# coef(deq.0)
summary(deq.0)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ group * (rGenHipp) + reps + shockCond + (-1 + rGenHipp |  
##     subid) + (1 | subid)
##    Data: dCleanStandardized
## 
##      AIC      BIC   logLik deviance df.resid 
##   7514.9   7569.3  -3749.5   7498.9     6615 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.0622 -0.7018 -0.3698  0.7778  5.2359 
## 
## Random effects:
##  Groups  Name        Variance Std.Dev.
##  subid   rGenHipp    0.07214  0.2686  
##  subid.1 (Intercept) 1.00406  1.0020  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)     -0.42992    0.15771  -2.726  0.00641 ** 
## group1           0.44368    0.15772   2.813  0.00491 ** 
## rGenHipp         0.33467    0.05136   6.516 7.22e-11 ***
## reps1            0.39755    0.02880  13.803  < 2e-16 ***
## shockCond1       0.01950    0.02845   0.685  0.49305    
## group1:rGenHipp  0.09507    0.05134   1.852  0.06406 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1
## group1      -0.048                            
## rGenHipp    -0.004  0.007                     
## reps1       -0.013  0.014  0.002              
## shockCond1  -0.004  0.004  0.003  0.008       
## grp1:rGnHpp  0.006 -0.003 -0.048 -0.009 -0.005
fixef(deq.0)
##     (Intercept)          group1        rGenHipp           reps1 
##     -0.42992200      0.44368074      0.33466534      0.39754889 
##      shockCond1 group1:rGenHipp 
##      0.01950378      0.09506868
fixef(deq.0)[3] # overall effect of hipp
##  rGenHipp 
## 0.3346653
fixef(deq.0)[6] # overall effect of hipp:group
## group1:rGenHipp 
##      0.09506868
# look at interaction of hipp * group
summary(glmer(pcorr ~ (rGenHipp) + reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (1|subid), 
             data=dCleanStandardized %>% filter(group == 'control'), 
      family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ (rGenHipp) + reps + shockCond + (-1 + rGenHipp | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized %>% filter(group == "control")
## 
##      AIC      BIC   logLik deviance df.resid 
##   3969.8   4006.8  -1978.9   3957.8     3547 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.2453 -0.6941  0.2142  0.7092  4.4509 
## 
## Random effects:
##  Groups  Name        Variance Std.Dev.
##  subid   rGenHipp    0.08692  0.2948  
##  subid.1 (Intercept) 1.42038  1.1918  
## Number of obs: 3553, groups:  subid, 22
## 
## Fixed effects:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  0.01359    0.25749   0.053    0.958    
## rGenHipp     0.43188    0.07570   5.705 1.16e-08 ***
## reps1        0.43333    0.03975  10.901  < 2e-16 ***
## shockCond1   0.02095    0.03926   0.534    0.594    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) rGnHpp reps1 
## rGenHipp    0.003              
## reps1       0.001 -0.004       
## shockCond1  0.000 -0.001  0.005
summary(glmer(pcorr ~ (rGenHipp) + reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (1|subid), 
             data=dCleanStandardized %>% filter(group == 'stress'), 
      family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ (rGenHipp) + reps + shockCond + (-1 + rGenHipp | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized %>% filter(group == "stress")
## 
##      AIC      BIC   logLik deviance df.resid 
##   3547.3   3583.5  -1767.7   3535.3     3064 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.1307 -0.6966 -0.4657  0.9263  4.7099 
## 
## Random effects:
##  Groups  Name        Variance Std.Dev.
##  subid   rGenHipp    0.05503  0.2346  
##  subid.1 (Intercept) 0.55524  0.7451  
## Number of obs: 3070, groups:  subid, 20
## 
## Fixed effects:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept) -0.85812    0.17235  -4.979 6.39e-07 ***
## rGenHipp     0.23557    0.06801   3.464 0.000533 ***
## reps1        0.35696    0.04179   8.542  < 2e-16 ***
## shockCond1   0.01766    0.04132   0.427 0.669089    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) rGnHpp reps1 
## rGenHipp   -0.014              
## reps1      -0.033  0.010       
## shockCond1 -0.012  0.009  0.011
# polynomial interaction?
deq.0b<-glmer(pcorr ~ group*(poly(hipp_sig_z, 2)) + reps + shockCond +
               (-1 + poly(hipp_sig_z, 2)|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial")
coef(deq.0b)
## $subid
##        (Intercept)    group1 poly(hipp_sig_z, 2)1 poly(hipp_sig_z, 2)2
## ap100 -0.179719928 0.4489898            18.955811           0.67998499
## ap101  0.122599966 0.4489898            52.908495           7.39666695
## ap102 -0.801141710 0.4489898            18.981810           0.68512834
## ap103  0.481051461 0.4489898            59.173250           8.63599066
## ap104  1.620984480 0.4489898            31.504644           3.16245521
## ap105  0.592531646 0.4489898            37.827055           4.41318459
## ap107  0.782620511 0.4489898            43.473270           5.53014593
## ap108 -1.890145730 0.4489898             5.985579          -1.88584829
## ap109 -0.995578663 0.4489898            11.239920          -0.84640908
## ap110 -2.395724028 0.4489898            14.897408          -0.12286756
## ap111 -0.722131590 0.4489898            51.438805           7.10592636
## ap113 -0.645582988 0.4489898             7.258866          -1.63396029
## ap114  0.072886031 0.4489898            14.630995          -0.17557115
## ap115 -0.522147636 0.4489898            53.715034           7.55622042
## ap116  1.621008256 0.4489898            32.417512           3.34304279
## ap117 -0.382707518 0.4489898            36.592067           4.16887289
## ap118 -0.992029054 0.4489898            49.228797           6.66873197
## ap119  0.414235274 0.4489898            20.525964           0.99060026
## ap120 -0.610417981 0.4489898            37.600349           4.36833667
## ap121 -1.824911605 0.4489898           -19.022156          -6.83299754
## ap122 -0.141853246 0.4489898            12.199591          -0.65656260
## ap150  0.106077938 0.4489898            46.295246           6.08840274
## ap152 -0.643696928 0.4489898            38.203901           4.48773441
## ap153 -0.937262784 0.4489898             9.900484          -1.11138302
## ap154 -0.513365474 0.4489898            13.648573          -0.36991790
## ap155 -0.516737748 0.4489898            15.131911          -0.07647738
## ap157 -0.359096351 0.4489898            46.675166           6.16356003
## ap158 -2.970970431 0.4489898            14.406755          -0.21993103
## ap159 -0.396201275 0.4489898            27.995848           2.46832827
## ap160 -0.014873925 0.4489898            10.163190          -1.05941341
## ap161 -1.164609106 0.4489898             9.358487          -1.21860362
## ap162 -0.622031049 0.4489898             6.351879          -1.81338423
## ap163  1.155909577 0.4489898            46.360286           6.10126907
## ap164  0.476996285 0.4489898            26.667038           2.20545693
## ap165 -0.003155807 0.4489898            62.478610           9.28987303
## ap166  0.219122524 0.4489898            14.177352          -0.26531309
## ap167 -0.706533023 0.4489898            29.757268           2.81678057
## ap169  0.185149007 0.4489898             2.241981          -2.62642458
## ap170  0.242310467 0.4489898            40.032914           4.84955847
## ap171 -0.988071847 0.4489898            40.776270           4.99661219
## ap172 -1.483956181 0.4489898            32.280958           3.31602923
## ap173 -2.321621448 0.4489898            38.832794           4.61214471
##           reps1 shockCond1 group1:poly(hipp_sig_z, 2)1
## ap100 0.3967185 0.02083239                    8.113781
## ap101 0.3967185 0.02083239                    8.113781
## ap102 0.3967185 0.02083239                    8.113781
## ap103 0.3967185 0.02083239                    8.113781
## ap104 0.3967185 0.02083239                    8.113781
## ap105 0.3967185 0.02083239                    8.113781
## ap107 0.3967185 0.02083239                    8.113781
## ap108 0.3967185 0.02083239                    8.113781
## ap109 0.3967185 0.02083239                    8.113781
## ap110 0.3967185 0.02083239                    8.113781
## ap111 0.3967185 0.02083239                    8.113781
## ap113 0.3967185 0.02083239                    8.113781
## ap114 0.3967185 0.02083239                    8.113781
## ap115 0.3967185 0.02083239                    8.113781
## ap116 0.3967185 0.02083239                    8.113781
## ap117 0.3967185 0.02083239                    8.113781
## ap118 0.3967185 0.02083239                    8.113781
## ap119 0.3967185 0.02083239                    8.113781
## ap120 0.3967185 0.02083239                    8.113781
## ap121 0.3967185 0.02083239                    8.113781
## ap122 0.3967185 0.02083239                    8.113781
## ap150 0.3967185 0.02083239                    8.113781
## ap152 0.3967185 0.02083239                    8.113781
## ap153 0.3967185 0.02083239                    8.113781
## ap154 0.3967185 0.02083239                    8.113781
## ap155 0.3967185 0.02083239                    8.113781
## ap157 0.3967185 0.02083239                    8.113781
## ap158 0.3967185 0.02083239                    8.113781
## ap159 0.3967185 0.02083239                    8.113781
## ap160 0.3967185 0.02083239                    8.113781
## ap161 0.3967185 0.02083239                    8.113781
## ap162 0.3967185 0.02083239                    8.113781
## ap163 0.3967185 0.02083239                    8.113781
## ap164 0.3967185 0.02083239                    8.113781
## ap165 0.3967185 0.02083239                    8.113781
## ap166 0.3967185 0.02083239                    8.113781
## ap167 0.3967185 0.02083239                    8.113781
## ap169 0.3967185 0.02083239                    8.113781
## ap170 0.3967185 0.02083239                    8.113781
## ap171 0.3967185 0.02083239                    8.113781
## ap172 0.3967185 0.02083239                    8.113781
## ap173 0.3967185 0.02083239                    8.113781
##       group1:poly(hipp_sig_z, 2)2
## ap100                    6.283574
## ap101                    6.283574
## ap102                    6.283574
## ap103                    6.283574
## ap104                    6.283574
## ap105                    6.283574
## ap107                    6.283574
## ap108                    6.283574
## ap109                    6.283574
## ap110                    6.283574
## ap111                    6.283574
## ap113                    6.283574
## ap114                    6.283574
## ap115                    6.283574
## ap116                    6.283574
## ap117                    6.283574
## ap118                    6.283574
## ap119                    6.283574
## ap120                    6.283574
## ap121                    6.283574
## ap122                    6.283574
## ap150                    6.283574
## ap152                    6.283574
## ap153                    6.283574
## ap154                    6.283574
## ap155                    6.283574
## ap157                    6.283574
## ap158                    6.283574
## ap159                    6.283574
## ap160                    6.283574
## ap161                    6.283574
## ap162                    6.283574
## ap163                    6.283574
## ap164                    6.283574
## ap165                    6.283574
## ap166                    6.283574
## ap167                    6.283574
## ap169                    6.283574
## ap170                    6.283574
## ap171                    6.283574
## ap172                    6.283574
## ap173                    6.283574
## 
## attr(,"class")
## [1] "coef.mer"
summary(deq.0b)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ group * (poly(hipp_sig_z, 2)) + reps + shockCond + (-1 +  
##     poly(hipp_sig_z, 2) | subid) + (1 | subid)
##    Data: dCleanStandardized
## 
##      AIC      BIC   logLik deviance df.resid 
##   7514.3   7595.9  -3745.1   7490.3     6611 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1524 -0.7027 -0.3714  0.7828  5.2445 
## 
## Random effects:
##  Groups  Name                 Variance Std.Dev. Corr
##  subid   poly(hipp_sig_z, 2)1 500.80   22.379       
##          poly(hipp_sig_z, 2)2  19.60    4.427   1.00
##  subid.1 (Intercept)            1.01    1.005       
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                 -0.42550    0.15817  -2.690  0.00714 ** 
## group1                       0.44899    0.15817   2.839  0.00453 ** 
## poly(hipp_sig_z, 2)1        27.95865    4.25162   6.576 4.83e-11 ***
## poly(hipp_sig_z, 2)2         2.46097    2.65616   0.927  0.35418    
## reps1                        0.39672    0.02882  13.763  < 2e-16 ***
## shockCond1                   0.02083    0.02849   0.731  0.46459    
## group1:poly(hipp_sig_z, 2)1  8.11378    4.24576   1.911  0.05600 .  
## group1:poly(hipp_sig_z, 2)2  6.28357    2.62071   2.398  0.01650 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 p(__,2)1 p(__,2)2 reps1  shckC1 g1:(__,2)1
## group1      -0.048                                                  
## ply(h__,2)1 -0.002  0.010                                           
## ply(h__,2)2  0.012  0.003  0.203                                    
## reps1       -0.013  0.014  0.003    0.000                           
## shockCond1  -0.004  0.004  0.003    0.013    0.008                  
## gr1:(__,2)1  0.009 -0.002 -0.052    0.086   -0.008 -0.003           
## gr1:(__,2)2  0.002  0.011  0.083   -0.059   -0.009  0.011  0.204
summary(glmer(pcorr ~ (poly(hipp_sig_z, 2)) + reps + shockCond +
               (-1 + poly(hipp_sig_z, 2)|subid) + 
               (1|subid), 
             data=dCleanStandardized %>% filter(group == 'control'), 
             family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ (poly(hipp_sig_z, 2)) + reps + shockCond + (-1 + poly(hipp_sig_z,  
##     2) | subid) + (1 | subid)
##    Data: dCleanStandardized %>% filter(group == "control")
## 
##      AIC      BIC   logLik deviance df.resid 
##   3968.8   4024.4  -1975.4   3950.8     3544 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.3474 -0.6912  0.1892  0.7102  4.2193 
## 
## Random effects:
##  Groups  Name                 Variance Std.Dev. Corr
##  subid   poly(hipp_sig_z, 2)1 333.461  18.261       
##          poly(hipp_sig_z, 2)2  15.149   3.892   1.00
##  subid.1 (Intercept)            1.431   1.196       
## Number of obs: 3553, groups:  subid, 22
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)           0.02471    0.25848   0.096   0.9238    
## poly(hipp_sig_z, 2)1 26.28925    4.63369   5.674  1.4e-08 ***
## poly(hipp_sig_z, 2)2  6.47642    2.69315   2.405   0.0162 *  
## reps1                 0.43057    0.03979  10.822  < 2e-16 ***
## shockCond1            0.02282    0.03932   0.580   0.5617    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) p(__,2)1 p(__,2)2 reps1 
## ply(h__,2)1  0.007                         
## ply(h__,2)2  0.014  0.324                  
## reps1        0.001 -0.004   -0.014         
## shockCond1   0.000 -0.002    0.021    0.006
summary(glmer(pcorr ~ (poly(hipp_sig_z, 2)) + reps + shockCond +
               (-1 + poly(hipp_sig_z, 2)|subid) + 
               (1|subid), 
             data=dCleanStandardized %>% filter(group == 'stress'), 
             family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ (poly(hipp_sig_z, 2)) + reps + shockCond + (-1 + poly(hipp_sig_z,  
##     2) | subid) + (1 | subid)
##    Data: dCleanStandardized %>% filter(group == "stress")
## 
##      AIC      BIC   logLik deviance df.resid 
##   3550.2   3604.5  -1766.1   3532.2     3061 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.1385 -0.6904 -0.4658  0.9173  4.7233 
## 
## Random effects:
##  Groups  Name                 Variance Std.Dev. Corr
##  subid   poly(hipp_sig_z, 2)1 174.8915 13.2247      
##          poly(hipp_sig_z, 2)2  58.6042  7.6553  0.14
##  subid.1 (Intercept)            0.5604  0.7486      
## Number of obs: 3070, groups:  subid, 20
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -0.86305    0.17317  -4.984 6.23e-07 ***
## poly(hipp_sig_z, 2)1 13.74035    3.82913   3.588 0.000333 ***
## poly(hipp_sig_z, 2)2 -3.34795    3.17916  -1.053 0.292299    
## reps1                 0.36092    0.04201   8.592  < 2e-16 ***
## shockCond1            0.01843    0.04144   0.445 0.656473    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) p(__,2)1 p(__,2)2 reps1 
## ply(h__,2)1 -0.018                         
## ply(h__,2)2  0.016 -0.029                  
## reps1       -0.033  0.015   -0.002         
## shockCond1  -0.012  0.005    0.003    0.012
# exploratory check: is there an interaction between reps and hipp?
summary(glmer(pcorr ~ group*(rGenHipp) + reps + shockCond + rGenHipp:reps +
               (-1 + rGenHipp|subid) + 
               # (-1 + rGenHipp:reps|subid) + # remove to converge
               (1|subid), 
             data=dCleanStandardized, family = "binomial",
             control=glmerControl(optimizer='Nelder_Mead')))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ group * (rGenHipp) + reps + shockCond + rGenHipp:reps +  
##     (-1 + rGenHipp | subid) + (1 | subid)
##    Data: dCleanStandardized
## Control: glmerControl(optimizer = "Nelder_Mead")
## 
##      AIC      BIC   logLik deviance df.resid 
##   7516.7   7577.8  -3749.3   7498.7     6614 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.0897 -0.7009 -0.3689  0.7791  5.2180 
## 
## Random effects:
##  Groups  Name        Variance Std.Dev.
##  subid   rGenHipp    0.07266  0.2696  
##  subid.1 (Intercept) 1.00441  1.0022  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)     -0.43003    0.15774  -2.726  0.00641 ** 
## group1           0.44348    0.15775   2.811  0.00493 ** 
## rGenHipp         0.33363    0.05152   6.476 9.44e-11 ***
## reps1            0.39741    0.02880  13.797  < 2e-16 ***
## shockCond1       0.01922    0.02846   0.675  0.49943    
## group1:rGenHipp  0.09590    0.05149   1.862  0.06253 .  
## rGenHipp:reps1   0.01562    0.02973   0.525  0.59940    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1 gr1:GH
## group1      -0.048                                   
## rGenHipp    -0.003  0.007                            
## reps1       -0.012  0.014  0.001                     
## shockCond1  -0.004  0.004  0.004  0.008              
## grp1:rGnHpp  0.006 -0.003 -0.049 -0.008 -0.005       
## rGnHpp:rps1 -0.002 -0.002 -0.037 -0.007 -0.019  0.031

Full model, controlling for VTC reinstatement

# triple check zstats are same
# summary(glmer(pcorr ~ group*(hipp_sig_z + vtc_logit_z) + reps + shockCond +
#                (-1 + hipp_sig_z|subid) + 
#                (-1 + vtc_logit_z|subid) + 
#                (1|subid), 
#              data=dCleanStandardized, family = "binomial"))

# effect of things on subsequent memory
deq.1<-glmer(pcorr ~ group*(rGenHipp + ERActUnsigned) + reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (-1 + ERActUnsigned|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial")
# uncorrelate random slopes and intercepts
summary(deq.1)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ group * (rGenHipp + ERActUnsigned) + reps + shockCond +  
##     (-1 + rGenHipp | subid) + (-1 + ERActUnsigned | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized
## 
##      AIC      BIC   logLik deviance df.resid 
##   7428.4   7503.1  -3703.2   7406.4     6612 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1434 -0.6772 -0.3542  0.7519  5.0011 
## 
## Random effects:
##  Groups  Name          Variance Std.Dev.
##  subid   rGenHipp      0.07081  0.2661  
##  subid.1 ERActUnsigned 0.04681  0.2164  
##  subid.2 (Intercept)   1.03744  1.0186  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -0.44188    0.16030  -2.757  0.00584 ** 
## group1                0.44877    0.16030   2.800  0.00512 ** 
## rGenHipp              0.26223    0.05210   5.034 4.81e-07 ***
## ERActUnsigned         0.26422    0.04601   5.743 9.32e-09 ***
## reps1                 0.38684    0.02916  13.264  < 2e-16 ***
## shockCond1            0.02031    0.02875   0.707  0.47984    
## group1:rGenHipp       0.12063    0.05208   2.316  0.02055 *  
## group1:ERActUnsigned -0.03333    0.04600  -0.725  0.46872    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp ERActU reps1  shckC1 gr1:GH
## group1      -0.049                                          
## rGenHipp    -0.002  0.005                                   
## ERActUnsgnd -0.008  0.005 -0.110                            
## reps1       -0.013  0.013  0.007 -0.019                     
## shockCond1  -0.004  0.005  0.003  0.003  0.010              
## grp1:rGnHpp  0.004 -0.001 -0.061  0.036 -0.010 -0.006       
## grp1:ERActU  0.005 -0.008  0.036 -0.071  0.005  0.001 -0.110
fixef(deq.1)
##          (Intercept)               group1             rGenHipp 
##          -0.44187904           0.44876921           0.26222980 
##        ERActUnsigned                reps1           shockCond1 
##           0.26422122           0.38683695           0.02031445 
##      group1:rGenHipp group1:ERActUnsigned 
##           0.12062548          -0.03332887
fixef(deq.1)[4] # subs ~ VTC direct effect 
## ERActUnsigned 
##     0.2642212
fixef(deq.1)[3] # subs ~ hipp direct effect 
##  rGenHipp 
## 0.2622298
fixef(deq.1)[7] # hipp:group interaction on pcorr direct
## group1:rGenHipp 
##       0.1206255
summary(deq.1)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ group * (rGenHipp + ERActUnsigned) + reps + shockCond +  
##     (-1 + rGenHipp | subid) + (-1 + ERActUnsigned | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized
## 
##      AIC      BIC   logLik deviance df.resid 
##   7428.4   7503.1  -3703.2   7406.4     6612 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1434 -0.6772 -0.3542  0.7519  5.0011 
## 
## Random effects:
##  Groups  Name          Variance Std.Dev.
##  subid   rGenHipp      0.07081  0.2661  
##  subid.1 ERActUnsigned 0.04681  0.2164  
##  subid.2 (Intercept)   1.03744  1.0186  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -0.44188    0.16030  -2.757  0.00584 ** 
## group1                0.44877    0.16030   2.800  0.00512 ** 
## rGenHipp              0.26223    0.05210   5.034 4.81e-07 ***
## ERActUnsigned         0.26422    0.04601   5.743 9.32e-09 ***
## reps1                 0.38684    0.02916  13.264  < 2e-16 ***
## shockCond1            0.02031    0.02875   0.707  0.47984    
## group1:rGenHipp       0.12063    0.05208   2.316  0.02055 *  
## group1:ERActUnsigned -0.03333    0.04600  -0.725  0.46872    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp ERActU reps1  shckC1 gr1:GH
## group1      -0.049                                          
## rGenHipp    -0.002  0.005                                   
## ERActUnsgnd -0.008  0.005 -0.110                            
## reps1       -0.013  0.013  0.007 -0.019                     
## shockCond1  -0.004  0.005  0.003  0.003  0.010              
## grp1:rGnHpp  0.004 -0.001 -0.061  0.036 -0.010 -0.006       
## grp1:ERActU  0.005 -0.008  0.036 -0.071  0.005  0.001 -0.110
# quick: what about "b" -- effect of VTC on pcorr
summary(glmer(pcorr ~ group*(ERActUnsigned) + reps + shockCond +
               (-1 + ERActUnsigned|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ group * (ERActUnsigned) + reps + shockCond + (-1 + ERActUnsigned |  
##     subid) + (1 | subid)
##    Data: dCleanStandardized
## 
##      AIC      BIC   logLik deviance df.resid 
##   7550.8   7605.1  -3767.4   7534.8     6615 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8002 -0.6986 -0.3596  0.7835  5.6495 
## 
## Random effects:
##  Groups  Name          Variance Std.Dev.
##  subid   ERActUnsigned 0.04786  0.2188  
##  subid.1 (Intercept)   0.99038  0.9952  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                       Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -0.441580   0.156672  -2.818  0.00482 ** 
## group1                0.436634   0.156660   2.787  0.00532 ** 
## ERActUnsigned         0.326077   0.045059   7.237  4.6e-13 ***
## reps1                 0.389862   0.028704  13.582  < 2e-16 ***
## shockCond1            0.020818   0.028332   0.735  0.46246    
## group1:ERActUnsigned -0.006766   0.045038  -0.150  0.88059    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 ERActU reps1  shckC1
## group1      -0.049                            
## ERActUnsgnd -0.009  0.006                     
## reps1       -0.013  0.013 -0.017              
## shockCond1  -0.004  0.005  0.004  0.008       
## grp1:ERActU  0.006 -0.009 -0.057  0.003 -0.002
# quadratic effect?
summary(glmer(pcorr ~ group*(poly(vtc_logit_z, 2)) + reps + shockCond +
               (-1 + poly(vtc_logit_z, 2)|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial",
             control=glmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5))))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ group * (poly(vtc_logit_z, 2)) + reps + shockCond + (-1 +  
##     poly(vtc_logit_z, 2) | subid) + (1 | subid)
##    Data: dCleanStandardized
## Control: 
## glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##   7546.3   7627.9  -3761.1   7522.3     6611 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.6628 -0.7041 -0.3541  0.7701  5.7804 
## 
## Random effects:
##  Groups  Name                  Variance Std.Dev. Corr 
##  subid   poly(vtc_logit_z, 2)1 376.4429 19.4021       
##          poly(vtc_logit_z, 2)2  83.4432  9.1347  -0.12
##  subid.1 (Intercept)             0.9994  0.9997       
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                              Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                  -0.44809    0.15740  -2.847  0.00442 ** 
## group1                        0.43822    0.15737   2.785  0.00536 ** 
## poly(vtc_logit_z, 2)1        27.67339    3.80521   7.273 3.53e-13 ***
## poly(vtc_logit_z, 2)2        -8.04984    2.87238  -2.803  0.00507 ** 
## reps1                         0.39246    0.02881  13.622  < 2e-16 ***
## shockCond1                    0.02150    0.02843   0.756  0.44944    
## group1:poly(vtc_logit_z, 2)1 -0.85992    3.77090  -0.228  0.81961    
## group1:poly(vtc_logit_z, 2)2 -1.51218    2.83373  -0.534  0.59360    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 p(__,2)1 p(__,2)2 reps1  shckC1 g1:(__,2)1
## group1      -0.049                                                  
## ply(v__,2)1 -0.013  0.007                                           
## ply(v__,2)2  0.012 -0.004 -0.123                                    
## reps1       -0.013  0.014 -0.013   -0.021                           
## shockCond1  -0.004  0.005  0.005   -0.006    0.008                  
## gr1:(__,2)1  0.007 -0.011 -0.054    0.024    0.000 -0.002           
## gr1:(__,2)2 -0.004  0.010  0.024   -0.041    0.016  0.022 -0.106
# interrogate interaction
summary(glmer(pcorr ~ (rGenHipp + ERActUnsigned) + reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (-1 + ERActUnsigned|subid) + 
               (1|subid), 
             data=dCleanStandardized %>% filter(group == 'control'), 
             family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ (rGenHipp + ERActUnsigned) + reps + shockCond + (-1 +  
##     rGenHipp | subid) + (-1 + ERActUnsigned | subid) + (1 | subid)
##    Data: dCleanStandardized %>% filter(group == "control")
## 
##      AIC      BIC   logLik deviance df.resid 
##   3927.6   3977.0  -1955.8   3911.6     3545 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.3056 -0.6773  0.2169  0.6892  4.2819 
## 
## Random effects:
##  Groups  Name          Variance Std.Dev.
##  subid   rGenHipp      0.08969  0.2995  
##  subid.1 ERActUnsigned 0.06196  0.2489  
##  subid.2 (Intercept)   1.46419  1.2100  
## Number of obs: 3553, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error z value Pr(>|z|)    
## (Intercept)   0.005957   0.261413   0.023 0.981821    
## rGenHipp      0.385538   0.077465   4.977 6.46e-07 ***
## ERActUnsigned 0.231443   0.068316   3.388 0.000704 ***
## reps1         0.428169   0.040285  10.628  < 2e-16 ***
## shockCond1    0.023858   0.039666   0.601 0.547522    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) rGnHpp ERActU reps1 
## rGenHipp     0.003                     
## ERActUnsgnd -0.004 -0.069              
## reps1        0.001  0.000 -0.011       
## shockCond1   0.000 -0.002  0.004  0.007
summary(glmer(pcorr ~ (rGenHipp + ERActUnsigned) + reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (-1 + ERActUnsigned|subid) + 
               (1|subid), 
             data=dCleanStandardized %>% filter(group == 'stress'), 
             family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ (rGenHipp + ERActUnsigned) + reps + shockCond + (-1 +  
##     rGenHipp | subid) + (-1 + ERActUnsigned | subid) + (1 | subid)
##    Data: dCleanStandardized %>% filter(group == "stress")
## 
##      AIC      BIC   logLik deviance df.resid 
##   3503.9   3552.1  -1743.9   3487.9     3062 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.4914 -0.6757 -0.4465  0.8937  4.5946 
## 
## Random effects:
##  Groups  Name          Variance Std.Dev.
##  subid   rGenHipp      0.05127  0.2264  
##  subid.1 ERActUnsigned 0.03277  0.1810  
##  subid.2 (Intercept)   0.58093  0.7622  
## Number of obs: 3070, groups:  subid, 20
## 
## Fixed effects:
##               Estimate Std. Error z value Pr(>|z|)    
## (Intercept)   -0.87331    0.17621  -4.956 7.19e-07 ***
## rGenHipp       0.13802    0.06866   2.010   0.0444 *  
## ERActUnsigned  0.29547    0.06146   4.808 1.53e-06 ***
## reps1          0.34025    0.04231   8.042 8.82e-16 ***
## shockCond1     0.01644    0.04176   0.394   0.6939    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) rGnHpp ERActU reps1 
## rGenHipp    -0.008                     
## ERActUnsgnd -0.017 -0.160              
## reps1       -0.031  0.018 -0.029       
## shockCond1  -0.011  0.010  0.001  0.014
# poly?
# both linear and quadratic interactions
summary(glmer(pcorr ~ group*(poly(hipp_sig_z, 2) + ERActUnsigned) +
                reps + shockCond +
               (-1 + poly(hipp_sig_z, 2)|subid) +
               (-1 + ERActUnsigned|subid) +
               (1|subid),
             data=dCleanStandardized, family = "binomial",
             control=glmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5))))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ group * (poly(hipp_sig_z, 2) + ERActUnsigned) + reps +  
##     shockCond + (-1 + poly(hipp_sig_z, 2) | subid) + (-1 + ERActUnsigned |  
##     subid) + (1 | subid)
##    Data: dCleanStandardized
## Control: 
## glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##   7428.1   7530.1  -3699.1   7398.1     6608 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.2373 -0.6744 -0.3533  0.7554  4.9623 
## 
## Random effects:
##  Groups  Name                 Variance  Std.Dev. Corr
##  subid   poly(hipp_sig_z, 2)1 493.62983 22.2178      
##          poly(hipp_sig_z, 2)2  23.08107  4.8043  0.48
##  subid.1 ERActUnsigned          0.04661  0.2159      
##  subid.2 (Intercept)            1.04345  1.0215      
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                 -0.43867    0.16078  -2.728  0.00636 ** 
## group1                       0.45414    0.16077   2.825  0.00473 ** 
## poly(hipp_sig_z, 2)1        22.17829    4.20261   5.277 1.31e-07 ***
## poly(hipp_sig_z, 2)2         2.33975    2.70260   0.866  0.38663    
## ERActUnsigned                0.26556    0.04602   5.771 7.89e-09 ***
## reps1                        0.38623    0.02921  13.221  < 2e-16 ***
## shockCond1                   0.02184    0.02879   0.758  0.44823    
## group1:poly(hipp_sig_z, 2)1  9.96197    4.20164   2.371  0.01774 *  
## group1:poly(hipp_sig_z, 2)2  6.74722    2.64882   2.547  0.01086 *  
## group1:ERActUnsigned        -0.03230    0.04596  -0.703  0.48219    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 p(__,2)1 p(__,2)2 ERActU reps1  shckC1
## group1      -0.049                                              
## ply(h__,2)1 -0.001  0.007                                       
## ply(h__,2)2  0.013  0.002  0.083                                
## ERActUnsgnd -0.009  0.005 -0.102    0.003                       
## reps1       -0.013  0.013  0.009   -0.005   -0.017              
## shockCond1  -0.004  0.005  0.003    0.014    0.004  0.010       
## gr1:(__,2)1  0.007  0.000 -0.065    0.078    0.031 -0.010 -0.005
## gr1:(__,2)2  0.001  0.011  0.067   -0.048    0.013 -0.006  0.012
## grp1:ERActU  0.005 -0.008  0.033    0.010   -0.070  0.005  0.001
##             g1:(__,2)1 g1:(__,2)2
## group1                           
## ply(h__,2)1                      
## ply(h__,2)2                      
## ERActUnsgnd                      
## reps1                            
## shockCond1                       
## gr1:(__,2)1                      
## gr1:(__,2)2  0.093               
## grp1:ERActU -0.105      0.008
# Fixed effects:
#                             Estimate Std. Error z value Pr(>|z|)    
# (Intercept)                 -0.43867    0.16078  -2.728  0.00636 ** 
# group1                       0.45414    0.16077   2.825  0.00473 ** 
# poly(hipp_sig_z, 2)1        22.17829    4.20261   5.277 1.31e-07 ***
# poly(hipp_sig_z, 2)2         2.33975    2.70260   0.866  0.38663    
# ERActUnsigned                0.26556    0.04602   5.771 7.89e-09 ***
# reps1                        0.38623    0.02921  13.221  < 2e-16 ***
# shockCond1                   0.02184    0.02879   0.758  0.44823    
# group1:poly(hipp_sig_z, 2)1  9.96197    4.20164   2.371  0.01774 *  
# group1:poly(hipp_sig_z, 2)2  6.74722    2.64882   2.547  0.01086 *  
# group1:ERActUnsigned        -0.03230    0.04596  -0.703  0.48219    
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1



# holds w/simple effects?
#controls:
contrasts(dCleanStandardized$group) = c(0,1); contrasts(dCleanStandardized$group)
##         [,1]
## control    0
## stress     1
summary(glmer(pcorr ~ group*(rGenHipp + ERActUnsigned) + reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (-1 + ERActUnsigned|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial",
             control=glmerControl(optimizer="bobyqa",
                                  optCtrl=list(maxfun=2e5))))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ group * (rGenHipp + ERActUnsigned) + reps + shockCond +  
##     (-1 + rGenHipp | subid) + (-1 + ERActUnsigned | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized
## Control: 
## glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##   7428.4   7503.1  -3703.2   7406.4     6612 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1434 -0.6772 -0.3542  0.7519  5.0012 
## 
## Random effects:
##  Groups  Name          Variance Std.Dev.
##  subid   rGenHipp      0.07081  0.2661  
##  subid.1 ERActUnsigned 0.04681  0.2163  
##  subid.2 (Intercept)   1.03745  1.0186  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                       Estimate Std. Error z value Pr(>|z|)    
## (Intercept)           0.006883   0.221105   0.031 0.975164    
## group1               -0.897553   0.320598  -2.800 0.005116 ** 
## rGenHipp              0.382864   0.071379   5.364 8.15e-08 ***
## ERActUnsigned         0.230903   0.062699   3.683 0.000231 ***
## reps1                 0.386842   0.029164  13.264  < 2e-16 ***
## shockCond1            0.020312   0.028751   0.706 0.479893    
## group1:rGenHipp      -0.241264   0.104165  -2.316 0.020549 *  
## group1:ERActUnsigned  0.066640   0.091993   0.724 0.468819    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp ERActU reps1  shckC1 gr1:GH
## group1      -0.690                                          
## rGenHipp     0.003 -0.002                                   
## ERActUnsgnd -0.004  0.003 -0.079                            
## reps1        0.001 -0.013 -0.002 -0.010                     
## shockCond1   0.000 -0.005 -0.002  0.003  0.010              
## grp1:rGnHpp -0.002 -0.001 -0.685  0.054  0.010  0.006       
## grp1:ERActU  0.003 -0.008  0.054 -0.681 -0.005 -0.001 -0.110
#stress:
contrasts(dCleanStandardized$group) = c(1,0); contrasts(dCleanStandardized$group)
##         [,1]
## control    1
## stress     0
summary(glmer(pcorr ~ group*(rGenHipp + ERActUnsigned) + reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (-1 + ERActUnsigned|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial",
             control=glmerControl(optimizer="bobyqa",
                                  optCtrl=list(maxfun=2e5))))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ group * (rGenHipp + ERActUnsigned) + reps + shockCond +  
##     (-1 + rGenHipp | subid) + (-1 + ERActUnsigned | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized
## Control: 
## glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##   7428.4   7503.1  -3703.2   7406.4     6612 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1434 -0.6772 -0.3542  0.7519  5.0012 
## 
## Random effects:
##  Groups  Name          Variance Std.Dev.
##  subid   rGenHipp      0.07081  0.2661  
##  subid.1 ERActUnsigned 0.04681  0.2163  
##  subid.2 (Intercept)   1.03745  1.0186  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -0.89067    0.23215  -3.837 0.000125 ***
## group1                0.89755    0.32059   2.800 0.005115 ** 
## rGenHipp              0.14160    0.07588   1.866 0.062033 .  
## ERActUnsigned         0.29754    0.06733   4.419 9.92e-06 ***
## reps1                 0.38684    0.02916  13.264  < 2e-16 ***
## shockCond1            0.02031    0.02875   0.706 0.479892    
## group1:rGenHipp       0.24126    0.10416   2.316 0.020547 *  
## group1:ERActUnsigned -0.06664    0.09199  -0.724 0.468809    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp ERActU reps1  shckC1 gr1:GH
## group1      -0.724                                          
## rGenHipp    -0.006  0.004                                   
## ERActUnsgnd -0.012  0.009 -0.137                            
## reps1       -0.018  0.013  0.011 -0.016                     
## shockCond1  -0.006  0.005  0.006  0.001  0.010              
## grp1:rGnHpp  0.004 -0.001 -0.728  0.100 -0.010 -0.006       
## grp1:ERActU  0.009 -0.008  0.100 -0.732  0.005  0.001 -0.110
contrasts(dCleanStandardized$group) = c(1,-1); contrasts(dCleanStandardized$group)
##         [,1]
## control    1
## stress    -1
# what about if we model random slope for rep?
# need to add more iterations to converge
summary(glmer(pcorr ~ group*(rGenHipp + ERActUnsigned) + reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (-1 + ERActUnsigned|subid) + 
               (-1 + reps|subid) + 
               (1|subid), 
             control=glmerControl(optimizer="bobyqa",
                                  optCtrl=list(maxfun=2e5)), 
             data=dCleanStandardized, family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: pcorr ~ group * (rGenHipp + ERActUnsigned) + reps + shockCond +  
##     (-1 + rGenHipp | subid) + (-1 + ERActUnsigned | subid) +  
##     (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized
## Control: 
## glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##   7433.7   7528.8  -3702.8   7405.7     6609 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1754 -0.6746 -0.3556  0.7491  4.9960 
## 
## Random effects:
##  Groups  Name          Variance Std.Dev. Corr
##  subid   rGenHipp      0.07025  0.2651       
##  subid.1 ERActUnsigned 0.04727  0.2174       
##  subid.2 reps2         0.33529  0.5790       
##          reps4         0.33943  0.5826   0.96
##  subid.3 (Intercept)   0.71092  0.8432       
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -0.44157    0.16076  -2.747  0.00602 ** 
## group1                0.44801    0.16504   2.715  0.00664 ** 
## rGenHipp              0.26222    0.05198   5.044 4.56e-07 ***
## ERActUnsigned         0.26385    0.04615   5.717 1.08e-08 ***
## reps1                 0.38722    0.03230  11.989  < 2e-16 ***
## shockCond1            0.02025    0.02877   0.704  0.48139    
## group1:rGenHipp       0.12117    0.05197   2.331  0.01973 *  
## group1:ERActUnsigned -0.03337    0.04614  -0.723  0.46954    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp ERActU reps1  shckC1 gr1:GH
## group1      -0.057                                          
## rGenHipp    -0.002  0.005                                   
## ERActUnsgnd -0.008  0.003 -0.110                            
## reps1       -0.013  0.042  0.007 -0.019                     
## shockCond1  -0.004  0.003  0.003  0.003  0.008              
## grp1:rGnHpp  0.005 -0.003 -0.061  0.036 -0.009 -0.006       
## grp1:ERActU  0.004 -0.004  0.036 -0.071  0.007  0.001 -0.110
# interactions of reps * group/neural measures?
summary(glmer(pcorr ~ group*(rGenHipp + ERActUnsigned + reps) +
                reps:rGenHipp + reps:ERActUnsigned + shockCond +
               (-1 + rGenHipp|subid) + 
               (-1 + ERActUnsigned|subid) + 
               (1|subid), 
             control=glmerControl(optimizer="bobyqa",
                                  optCtrl=list(maxfun=2e5)), 
             data=dCleanStandardized, family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ group * (rGenHipp + ERActUnsigned + reps) + reps:rGenHipp +  
##     reps:ERActUnsigned + shockCond + (-1 + rGenHipp | subid) +  
##     (-1 + ERActUnsigned | subid) + (1 | subid)
##    Data: dCleanStandardized
## Control: 
## glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##   7428.1   7523.3  -3700.0   7400.1     6609 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.2453 -0.6740 -0.3502  0.7529  5.1570 
## 
## Random effects:
##  Groups  Name          Variance Std.Dev.
##  subid   rGenHipp      0.07134  0.2671  
##  subid.1 ERActUnsigned 0.04742  0.2178  
##  subid.2 (Intercept)   1.04263  1.0211  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                      Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -0.43734    0.16070  -2.721  0.00650 ** 
## group1                0.44567    0.16070   2.773  0.00555 ** 
## rGenHipp              0.25695    0.05228   4.915 8.87e-07 ***
## ERActUnsigned         0.27131    0.04629   5.861 4.59e-09 ***
## reps1                 0.38622    0.02926  13.200  < 2e-16 ***
## shockCond1            0.01938    0.02877   0.673  0.50066    
## group1:rGenHipp       0.12177    0.05222   2.332  0.01971 *  
## group1:ERActUnsigned -0.03907    0.04626  -0.845  0.39834    
## group1:reps1          0.04103    0.02923   1.404  0.16044    
## rGenHipp:reps1        0.03894    0.03115   1.250  0.21121    
## ERActUnsigned:reps1  -0.05958    0.03099  -1.922  0.05455 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp ERActU reps1  shckC1 gr1:GH g1:ERA grp1:1
## group1      -0.049                                                        
## rGenHipp    -0.001  0.005                                                 
## ERActUnsgnd -0.009  0.005 -0.111                                          
## reps1       -0.012  0.013  0.004 -0.012                                   
## shockCond1  -0.004  0.005  0.004  0.002  0.010                            
## grp1:rGnHpp  0.004 -0.001 -0.060  0.036 -0.005 -0.006                     
## grp1:ERActU  0.004 -0.009  0.036 -0.073  0.000  0.001 -0.108              
## group1:rps1  0.012 -0.012 -0.006  0.003 -0.058 -0.005  0.005 -0.014       
## rGnHpp:rps1  0.000 -0.002 -0.043  0.030  0.002 -0.018  0.022  0.009  0.032
## ERActUnsg:1 -0.005 -0.001  0.030 -0.073 -0.046  0.006  0.002  0.060  0.017
##             rGnH:1
## group1            
## rGenHipp          
## ERActUnsgnd       
## reps1             
## shockCond1        
## grp1:rGnHpp       
## grp1:ERActU       
## group1:rps1       
## rGnHpp:rps1       
## ERActUnsg:1 -0.255
# removed Rslope of hipp/vtc to converge

Full model, also controlling for inferior parietal reinstatment

# effect of more things on subsequent memory
deq.1b<-glmer(pcorr ~ group*(rGenHipp + ERActUnsigned + ERActUnsigned_infpar) +
                reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (-1 + ERActUnsigned|subid) + 
               (-1 + ERActUnsigned_infpar|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial",
             control=glmerControl(optimizer="bobyqa",
                                  optCtrl=list(maxfun=2e5))
             )
summary(deq.1b)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ group * (rGenHipp + ERActUnsigned + ERActUnsigned_infpar) +  
##     reps + shockCond + (-1 + rGenHipp | subid) + (-1 + ERActUnsigned |  
##     subid) + (-1 + ERActUnsigned_infpar | subid) + (1 | subid)
##    Data: dCleanStandardized
## Control: 
## glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##   7407.4   7502.6  -3689.7   7379.4     6609 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9916 -0.6730 -0.3464  0.7374  4.6640 
## 
## Random effects:
##  Groups  Name                 Variance Std.Dev.
##  subid   rGenHipp             0.06722  0.2593  
##  subid.1 ERActUnsigned        0.03461  0.1860  
##  subid.2 ERActUnsigned_infpar 0.03737  0.1933  
##  subid.3 (Intercept)          1.04625  1.0229  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                 -0.44617    0.16098  -2.772 0.005579 ** 
## group1                       0.45305    0.16098   2.814 0.004889 ** 
## rGenHipp                     0.25794    0.05143   5.015  5.3e-07 ***
## ERActUnsigned                0.17655    0.04782   3.692 0.000222 ***
## ERActUnsigned_infpar         0.15867    0.04799   3.306 0.000946 ***
## reps1                        0.38542    0.02930  13.152  < 2e-16 ***
## shockCond1                   0.02054    0.02886   0.712 0.476725    
## group1:rGenHipp              0.12203    0.05142   2.373 0.017636 *  
## group1:ERActUnsigned        -0.03229    0.04779  -0.676 0.499227    
## group1:ERActUnsigned_infpar -0.02038    0.04802  -0.424 0.671227    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp ERActU ERAcU_ reps1  shckC1 gr1:GH
## group1      -0.049                                                 
## rGenHipp    -0.002  0.005                                          
## ERActUnsgnd -0.005  0.003 -0.098                                   
## ERActUnsgn_ -0.005  0.003 -0.015 -0.344                            
## reps1       -0.013  0.014  0.006 -0.014 -0.007                     
## shockCond1  -0.005  0.005  0.004  0.001  0.003  0.011              
## grp1:rGnHpp  0.004 -0.001 -0.061  0.034  0.002 -0.012 -0.006       
## grp1:ERActU  0.003 -0.005  0.033 -0.026 -0.034  0.006 -0.005 -0.099
## grp1:ERAcU_  0.003 -0.005  0.003 -0.034 -0.009 -0.003  0.009 -0.015
##             gr1:ERAU
## group1              
## rGenHipp            
## ERActUnsgnd         
## ERActUnsgn_         
## reps1               
## shockCond1          
## grp1:rGnHpp         
## grp1:ERActU         
## grp1:ERAcU_ -0.344

Full model, also controlling for angular bold

# effect of more things on subsequent memory
deq.1c<-glmer(pcorr ~ group*(rGenHipp + ERActUnsigned + 
                               ERActUnsigned_infpar + rGenANG) +
                reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (-1 + ERActUnsigned|subid) + 
               (-1 + ERActUnsigned_infpar|subid) + 
                (-1 + rGenANG|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial",
             control=glmerControl(optimizer="bobyqa",
                                  optCtrl=list(maxfun=2e5))
             )
summary(deq.1c)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ group * (rGenHipp + ERActUnsigned + ERActUnsigned_infpar +  
##     rGenANG) + reps + shockCond + (-1 + rGenHipp | subid) + (-1 +  
##     ERActUnsigned | subid) + (-1 + ERActUnsigned_infpar | subid) +  
##     (-1 + rGenANG | subid) + (1 | subid)
##    Data: dCleanStandardized
## Control: 
## glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##   7378.9   7494.5  -3672.4   7344.9     6606 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.0248 -0.6645 -0.3405  0.7330  4.2568 
## 
## Random effects:
##  Groups  Name                 Variance Std.Dev.
##  subid   rGenHipp             0.04350  0.2086  
##  subid.1 ERActUnsigned        0.03190  0.1786  
##  subid.2 ERActUnsigned_infpar 0.03932  0.1983  
##  subid.3 rGenANG              0.05484  0.2342  
##  subid.4 (Intercept)          1.06627  1.0326  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                 -0.45274    0.16252  -2.786 0.005340 ** 
## group1                       0.45935    0.16252   2.827 0.004706 ** 
## rGenHipp                     0.16977    0.05036   3.371 0.000748 ***
## ERActUnsigned                0.17227    0.04755   3.623 0.000291 ***
## ERActUnsigned_infpar         0.15514    0.04885   3.176 0.001494 ** 
## rGenANG                      0.15682    0.05287   2.966 0.003017 ** 
## reps1                        0.38524    0.02949  13.063  < 2e-16 ***
## shockCond1                   0.01887    0.02900   0.651 0.515165    
## group1:rGenHipp              0.16772    0.05037   3.330 0.000869 ***
## group1:ERActUnsigned        -0.02377    0.04755  -0.500 0.617069    
## group1:ERActUnsigned_infpar -0.01650    0.04889  -0.338 0.735723    
## group1:rGenANG              -0.08447    0.05288  -1.597 0.110169    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp ERActU ERAcU_ rGnANG reps1  shckC1 gr1:GH
## group1      -0.049                                                        
## rGenHipp     0.000  0.002                                                 
## ERActUnsgnd -0.005  0.003 -0.074                                          
## ERActUnsgn_ -0.005  0.003 -0.010 -0.342                                   
## rGenANG     -0.004  0.005 -0.305 -0.046 -0.011                            
## reps1       -0.013  0.014  0.013 -0.011 -0.008 -0.014                     
## shockCond1  -0.004  0.005  0.005  0.003  0.004 -0.005  0.010              
## grp1:rGnHpp  0.001  0.000 -0.066  0.041  0.013  0.019 -0.002 -0.009       
## grp1:ERActU  0.002 -0.005  0.041 -0.023 -0.033 -0.014  0.011 -0.005 -0.074
## grp1:ERAcU_  0.003 -0.005  0.012 -0.033 -0.012 -0.012 -0.001  0.008 -0.010
## grp1:rGnANG  0.005 -0.004  0.020 -0.013 -0.015 -0.054 -0.016  0.005 -0.306
##             gr1:ERAU g1:ERAU_
## group1                       
## rGenHipp                     
## ERActUnsgnd                  
## ERActUnsgn_                  
## rGenANG                      
## reps1                        
## shockCond1                   
## grp1:rGnHpp                  
## grp1:ERActU                  
## grp1:ERAcU_ -0.342           
## grp1:rGnANG -0.049   -0.010

Full model, also controlling for rsp

# effect of more things on subsequent memory
deq.1d<-glmer(pcorr ~ group*(rGenHipp + ERActUnsigned + 
                               ERActUnsigned_infpar +
                               rGenANG + rGenRSP) +
                reps + shockCond +
               (-1 + rGenHipp|subid) + 
               (-1 + ERActUnsigned|subid) + 
               (-1 + ERActUnsigned_infpar|subid) + 
                (-1 + rGenANG|subid) + 
                (-1 + rGenRSP|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial",
             control=glmerControl(optimizer="bobyqa",
                                  optCtrl=list(maxfun=2e5))
             )
summary(deq.1d)
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ group * (rGenHipp + ERActUnsigned + ERActUnsigned_infpar +  
##     rGenANG + rGenRSP) + reps + shockCond + (-1 + rGenHipp |  
##     subid) + (-1 + ERActUnsigned | subid) + (-1 + ERActUnsigned_infpar |  
##     subid) + (-1 + rGenANG | subid) + (-1 + rGenRSP | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized
## Control: 
## glmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
##      AIC      BIC   logLik deviance df.resid 
##   7366.3   7502.3  -3663.1   7326.3     6603 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9383 -0.6668 -0.3338  0.7327  4.3757 
## 
## Random effects:
##  Groups  Name                 Variance Std.Dev.
##  subid   rGenHipp             0.04186  0.2046  
##  subid.1 ERActUnsigned        0.03044  0.1745  
##  subid.2 ERActUnsigned_infpar 0.03480  0.1865  
##  subid.3 rGenANG              0.04821  0.2196  
##  subid.4 rGenRSP              0.02844  0.1686  
##  subid.5 (Intercept)          1.07770  1.0381  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                 -0.45591    0.16338  -2.790 0.005263 ** 
## group1                       0.46311    0.16338   2.834 0.004590 ** 
## rGenHipp                     0.16191    0.05400   2.998 0.002715 ** 
## ERActUnsigned                0.17143    0.04869   3.521 0.000430 ***
## ERActUnsigned_infpar         0.14667    0.04869   3.013 0.002590 ** 
## rGenANG                      0.15892    0.05363   2.963 0.003045 ** 
## rGenRSP                      0.02246    0.05711   0.393 0.694145    
## reps1                        0.38519    0.02957  13.027  < 2e-16 ***
## shockCond1                   0.02142    0.02907   0.737 0.461313    
## group1:rGenHipp              0.25001    0.05405   4.625 3.74e-06 ***
## group1:ERActUnsigned         0.02260    0.04872   0.464 0.642784    
## group1:ERActUnsigned_infpar  0.02050    0.04875   0.420 0.674135    
## group1:rGenANG              -0.02591    0.05356  -0.484 0.628560    
## group1:rGenRSP              -0.20658    0.05735  -3.602 0.000316 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation matrix not shown by default, as p = 14 > 12.
## Use print(x, correlation=TRUE)  or
##   vcov(x)     if you need it

VTC reinstatement ~ hipp

deq.2<-lmer(ERActUnsigned ~ group*(rGenHipp) + reps + shockCond + pcorr + 
              (-1 + rGenHipp|subid)+
              (1|subid), 
            data=dCleanStandardized)
# uncorrelate random slopes and intercepts
summary(deq.2)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (rGenHipp) + reps + shockCond + pcorr +  
##     (-1 + rGenHipp | subid) + (1 | subid)
##    Data: dCleanStandardized
## 
## REML criterion at convergence: 18067.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7758 -0.6741 -0.0103  0.6306  4.5744 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    rGenHipp    0.03019  0.1738  
##  subid.1  (Intercept) 0.00000  0.0000  
##  Residual             0.88032  0.9383  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)      1.601e-02  1.175e-02  6.577e+03   1.363   0.1728    
## group1          -1.689e-02  1.177e-02  6.577e+03  -1.435   0.1514    
## rGenHipp         2.658e-01  2.927e-02  4.000e+01   9.079 2.92e-11 ***
## reps1            4.878e-02  1.173e-02  6.590e+03   4.157 3.27e-05 ***
## shockCond1      -3.628e-03  1.155e-02  6.583e+03  -0.314   0.7535    
## pcorr1           9.505e-02  1.225e-02  6.605e+03   7.762 9.77e-15 ***
## group1:rGenHipp -5.968e-02  2.924e-02  4.000e+01  -2.041   0.0479 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1 pcorr1
## group1      -0.104                                   
## rGenHipp    -0.009  0.010                            
## reps1       -0.029  0.033 -0.009                     
## shockCond1  -0.021  0.023  0.004  0.003              
## pcorr1       0.176 -0.187 -0.052 -0.158 -0.008       
## grp1:rGnHpp -0.003  0.003 -0.051 -0.010 -0.004 -0.016
fixef(deq.2)
##     (Intercept)          group1        rGenHipp           reps1 
##     0.016014200    -0.016887630     0.265782366     0.048777760 
##      shockCond1          pcorr1 group1:rGenHipp 
##    -0.003627942     0.095051299    -0.059683911
fixef(deq.2)[3] # VTC ~ hipp direct effect 
##  rGenHipp 
## 0.2657824
fixef(deq.2)[7] # VTC ~ group:hipp
## group1:rGenHipp 
##     -0.05968391
# interaction
summary(lmer(ERActUnsigned ~ rGenHipp + reps + shockCond + pcorr + 
              (-1 + rGenHipp|subid)+
              (1|subid), 
            data=dCleanStandardized %>% filter(group == 'control')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## ERActUnsigned ~ rGenHipp + reps + shockCond + pcorr + (-1 + rGenHipp |  
##     subid) + (1 | subid)
##    Data: dCleanStandardized %>% filter(group == "control")
## 
## REML criterion at convergence: 9822.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.2808 -0.6935 -0.0286  0.6454  4.4993 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    rGenHipp    0.0282   0.1679  
##  subid.1  (Intercept) 0.0000   0.0000  
##  Residual             0.9126   0.9553  
## Number of obs: 3553, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept) -7.584e-04  1.603e-02  3.527e+03  -0.047   0.9623    
## rGenHipp     2.089e-01  3.934e-02  2.100e+01   5.309 2.83e-05 ***
## reps1        4.146e-02  1.635e-02  3.534e+03   2.535   0.0113 *  
## shockCond1  -4.082e-03  1.606e-02  3.532e+03  -0.254   0.7993    
## pcorr1       8.214e-02  1.666e-02  3.544e+03   4.931 8.55e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) rGnHpp reps1  shckC1
## rGenHipp    0.001                     
## reps1       0.004 -0.019              
## shockCond1  0.002 -0.001  0.000       
## pcorr1     -0.011 -0.069 -0.167 -0.008
summary(lmer(ERActUnsigned ~ rGenHipp + reps + shockCond + pcorr + 
              (-1 + rGenHipp|subid)+
              (1|subid), 
            data=dCleanStandardized %>% filter(group == 'stress')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## ERActUnsigned ~ rGenHipp + reps + shockCond + pcorr + (-1 + rGenHipp |  
##     subid) + (1 | subid)
##    Data: dCleanStandardized %>% filter(group == "stress")
## 
## REML criterion at convergence: 8252
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8485 -0.6430  0.0051  0.6123  3.8242 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    rGenHipp    0.03276  0.1810  
##  subid.1  (Intercept) 0.00000  0.0000  
##  Residual             0.84316  0.9182  
## Number of obs: 3070, groups:  subid, 20
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  3.871e-02  1.774e-02  3.048e+03   2.182 0.029174 *  
## rGenHipp     3.239e-01  4.377e-02  1.890e+01   7.400 5.46e-07 ***
## reps1        5.736e-02  1.682e-02  3.053e+03   3.411 0.000657 ***
## shockCond1  -2.981e-03  1.662e-02  3.049e+03  -0.179 0.857643    
## pcorr1       1.120e-01  1.807e-02  3.057e+03   6.197 6.54e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) rGnHpp reps1  shckC1
## rGenHipp   -0.013                     
## reps1      -0.057  0.001              
## shockCond1 -0.042  0.008  0.007       
## pcorr1      0.355 -0.036 -0.147 -0.008
## double check with simple effects
# controls:
contrasts(dCleanStandardized$group) = c(0,1); contrasts(dCleanStandardized$group)
##         [,1]
## control    0
## stress     1
summary(lmer(ERActUnsigned ~ group*(rGenHipp) + reps + shockCond + pcorr + 
              (-1 + rGenHipp|subid)+
              (1|subid), 
            data=dCleanStandardized))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (rGenHipp) + reps + shockCond + pcorr +  
##     (-1 + rGenHipp | subid) + (1 | subid)
##    Data: dCleanStandardized
## 
## REML criterion at convergence: 18065
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7758 -0.6741 -0.0103  0.6306  4.5744 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    rGenHipp    0.03019  0.1738  
##  subid.1  (Intercept) 0.00000  0.0000  
##  Residual             0.88032  0.9383  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)     -8.734e-04  1.574e-02  6.576e+03  -0.055   0.9558    
## group1           3.378e-02  2.354e-02  6.577e+03   1.435   0.1514    
## rGenHipp         2.061e-01  4.031e-02  4.000e+01   5.112 8.45e-06 ***
## reps1            4.878e-02  1.173e-02  6.590e+03   4.157 3.27e-05 ***
## shockCond1      -3.628e-03  1.155e-02  6.583e+03  -0.314   0.7535    
## pcorr1           9.505e-02  1.225e-02  6.605e+03   7.762 9.77e-15 ***
## group1:rGenHipp  1.194e-01  5.847e-02  4.000e+01   2.041   0.0479 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1 pcorr1
## group1      -0.670                                   
## rGenHipp     0.000 -0.009                            
## reps1        0.003 -0.033 -0.013                     
## shockCond1   0.002 -0.023  0.000  0.003              
## pcorr1      -0.008  0.187 -0.050 -0.158 -0.008       
## grp1:rGnHpp  0.000  0.003 -0.688  0.010  0.004  0.016
# stress:
contrasts(dCleanStandardized$group) = c(1,0); contrasts(dCleanStandardized$group)
##         [,1]
## control    1
## stress     0
summary(lmer(ERActUnsigned ~ group*(rGenHipp) + reps + shockCond + pcorr + 
              (-1 + rGenHipp|subid)+
              (1|subid), 
            data=dCleanStandardized))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (rGenHipp) + reps + shockCond + pcorr +  
##     (-1 + rGenHipp | subid) + (1 | subid)
##    Data: dCleanStandardized
## 
## REML criterion at convergence: 18065
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7758 -0.6741 -0.0103  0.6306  4.5744 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    rGenHipp    0.03019  0.1738  
##  subid.1  (Intercept) 0.00000  0.0000  
##  Residual             0.88032  0.9383  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)      3.290e-02  1.747e-02  6.578e+03   1.883   0.0597 .  
## group1          -3.377e-02  2.354e-02  6.577e+03  -1.435   0.1514    
## rGenHipp         3.255e-01  4.241e-02  4.000e+01   7.674 2.16e-09 ***
## reps1            4.878e-02  1.173e-02  6.590e+03   4.157 3.27e-05 ***
## shockCond1      -3.628e-03  1.155e-02  6.583e+03  -0.314   0.7535    
## pcorr1           9.505e-02  1.225e-02  6.605e+03   7.762 9.77e-15 ***
## group1:rGenHipp -1.194e-01  5.847e-02  4.000e+01  -2.041   0.0479 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1 pcorr1
## group1      -0.744                                   
## rGenHipp    -0.006  0.005                            
## reps1       -0.042  0.033  0.001                     
## shockCond1  -0.030  0.023  0.005  0.003              
## pcorr1       0.244 -0.187 -0.025 -0.158 -0.008       
## grp1:rGnHpp -0.004  0.003 -0.724 -0.010 -0.004 -0.016
contrasts(dCleanStandardized$group) = c(1,-1); contrasts(dCleanStandardized$group)
##         [,1]
## control    1
## stress    -1
# look at raw reinstatement by median split of hipp signal
dat = dCleanStandardized %>%
  group_by(subid, group) %>%
  mutate(hipp_med = ntile(hipp_sig, 2)) %>%
  ungroup()

summary(lmer(vtc_logit ~ group + reps + shockCond + pcorr +
              (1|subid), 
            data=dat %>% filter(hipp_med == 1)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ group + reps + shockCond + pcorr + (1 | subid)
##    Data: dat %>% filter(hipp_med == 1)
## 
## REML criterion at convergence: 16074.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7813 -0.6517 -0.0127  0.6125  4.0562 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.1934   0.4398  
##  Residual             7.2823   2.6986  
## Number of obs: 3320, groups:  subid, 42
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept) -2.364e-01  8.391e-02  4.100e+01  -2.817 0.007407 ** 
## group1       2.483e-01  8.298e-02  3.900e+01   2.993 0.004751 ** 
## reps1        1.790e-01  4.770e-02  3.293e+03   3.754 0.000177 ***
## shockCond1  -5.679e-04  4.694e-02  3.284e+03  -0.012 0.990349    
## pcorr1       3.947e-01  5.256e-02  2.916e+03   7.510 7.84e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) group1 reps1  shckC1
## group1     -0.071                     
## reps1      -0.003  0.028              
## shockCond1 -0.008  0.013  0.019       
## pcorr1      0.173 -0.093 -0.163  0.003
summary(lmer(vtc_logit ~ group + reps + shockCond + pcorr + 
              (1|subid), 
            data=dat %>% filter(hipp_med == 2)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ group + reps + shockCond + pcorr + (1 | subid)
##    Data: dat %>% filter(hipp_med == 2)
## 
## REML criterion at convergence: 16015.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7916 -0.6354 -0.0294  0.6352  4.1681 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.2967   0.5447  
##  Residual             7.3053   2.7028  
## Number of obs: 3303, groups:  subid, 42
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)    0.91460    0.09657   40.00000   9.471 9.32e-12 ***
## group1        -0.07251    0.09715   41.00000  -0.746    0.460    
## reps1          0.08316    0.04796 3278.00000   1.734    0.083 .  
## shockCond1    -0.04257    0.04720 3269.00000  -0.902    0.367    
## pcorr1         0.39241    0.05312 2817.00000   7.387 1.97e-13 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) group1 reps1  shckC1
## group1     -0.058                     
## reps1      -0.029  0.012              
## shockCond1 -0.012  0.012 -0.013       
## pcorr1      0.035 -0.117 -0.170 -0.016
# what about rep effect?
summary(lmer(ERActUnsigned ~ group*(rGenHipp) + reps + shockCond + pcorr + 
              (-1 + rGenHipp|subid)+
              (-1 + reps|subid)+
              (1|subid), 
            data=dCleanStandardized))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (rGenHipp) + reps + shockCond + pcorr +  
##     (-1 + rGenHipp | subid) + (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized
## 
## REML criterion at convergence: 18065.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7981 -0.6664 -0.0129  0.6315  4.5756 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    rGenHipp    0.030154 0.17365       
##  subid.1  reps2       0.001565 0.03956       
##           reps4       0.002186 0.04675  -1.00
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.878495 0.93728       
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)      1.595e-02  1.175e-02  3.502e+03   1.358 0.174580    
## group1          -1.667e-02  1.177e-02  4.447e+03  -1.417 0.156661    
## rGenHipp         2.659e-01  2.926e-02  4.000e+01   9.089 2.84e-11 ***
## reps1            4.879e-02  1.348e-02  4.400e+01   3.619 0.000765 ***
## shockCond1      -3.667e-03  1.154e-02  6.548e+03  -0.318 0.750747    
## pcorr1           9.506e-02  1.225e-02  6.427e+03   7.762 9.77e-15 ***
## group1:rGenHipp -5.961e-02  2.922e-02  4.000e+01  -2.040 0.048041 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1 pcorr1
## group1      -0.104                                   
## rGenHipp    -0.009  0.010                            
## reps1       -0.002  0.029 -0.008                     
## shockCond1  -0.021  0.023  0.004  0.003              
## pcorr1       0.176 -0.187 -0.052 -0.137 -0.008       
## grp1:rGnHpp -0.003  0.003 -0.051 -0.008 -0.004 -0.016

Double check: does it matter if pcorr is included?

summary(lmer(ERActUnsigned ~ group*(rGenHipp) + reps + shockCond + pcorr +
              (-1 + rGenHipp|subid)+
              (1|subid), 
            data=dCleanStandardized))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (rGenHipp) + reps + shockCond + pcorr +  
##     (-1 + rGenHipp | subid) + (1 | subid)
##    Data: dCleanStandardized
## 
## REML criterion at convergence: 18067.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7758 -0.6741 -0.0103  0.6306  4.5744 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    rGenHipp    0.03019  0.1738  
##  subid.1  (Intercept) 0.00000  0.0000  
##  Residual             0.88032  0.9383  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)      1.601e-02  1.175e-02  6.577e+03   1.363   0.1728    
## group1          -1.689e-02  1.177e-02  6.577e+03  -1.435   0.1514    
## rGenHipp         2.658e-01  2.927e-02  4.000e+01   9.079 2.92e-11 ***
## reps1            4.878e-02  1.173e-02  6.590e+03   4.157 3.27e-05 ***
## shockCond1      -3.628e-03  1.155e-02  6.583e+03  -0.314   0.7535    
## pcorr1           9.505e-02  1.225e-02  6.605e+03   7.762 9.77e-15 ***
## group1:rGenHipp -5.968e-02  2.924e-02  4.000e+01  -2.041   0.0479 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1 pcorr1
## group1      -0.104                                   
## rGenHipp    -0.009  0.010                            
## reps1       -0.029  0.033 -0.009                     
## shockCond1  -0.021  0.023  0.004  0.003              
## pcorr1       0.176 -0.187 -0.052 -0.158 -0.008       
## grp1:rGnHpp -0.003  0.003 -0.051 -0.010 -0.004 -0.016
summary(lmer(ERActUnsigned ~ group*(rGenHipp) + reps + shockCond +
              (-1 + rGenHipp|subid)+
              (1|subid), 
            data=dCleanStandardized))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (rGenHipp) + reps + shockCond + (-1 +  
##     rGenHipp | subid) + (1 | subid)
##    Data: dCleanStandardized
## 
## REML criterion at convergence: 18120.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7816 -0.6721 -0.0054  0.6275  4.4647 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    rGenHipp    0.0313   0.1769  
##  subid.1  (Intercept) 0.0000   0.0000  
##  Residual             0.8881   0.9424  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)     -2.670e-05  1.161e-02  6.577e+03  -0.002   0.9982    
## group1           1.809e-04  1.161e-02  6.577e+03   0.016   0.9876    
## rGenHipp         2.777e-01  2.970e-02  4.000e+01   9.348 1.36e-11 ***
## reps1            6.315e-02  1.164e-02  6.591e+03   5.426 5.97e-08 ***
## shockCond1      -2.914e-03  1.160e-02  6.584e+03  -0.251   0.8018    
## group1:rGenHipp -5.609e-02  2.970e-02  4.000e+01  -1.888   0.0663 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1
## group1      -0.073                            
## rGenHipp     0.000  0.000                     
## reps1       -0.001  0.004 -0.017              
## shockCond1  -0.020  0.022  0.003  0.002       
## grp1:rGnHpp  0.000  0.000 -0.051 -0.012 -0.004
summary(lmer(ERActUnsigned ~ group*(rGenHipp*pcorr) + reps + shockCond +
              (-1 + rGenHipp|subid)+
               (-1 + pcorr|subid)+
               (-1 + rGenHipp:pcorr|subid)+
              (1|subid), 
            data=dCleanStandardized))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (rGenHipp * pcorr) + reps + shockCond +  
##     (-1 + rGenHipp | subid) + (-1 + pcorr | subid) + (-1 + rGenHipp:pcorr |  
##     subid) + (1 | subid)
##    Data: dCleanStandardized
## 
## REML criterion at convergence: 18066.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8435 -0.6710 -0.0169  0.6265  4.7053 
## 
## Random effects:
##  Groups   Name            Variance Std.Dev. Corr 
##  subid    rGenHipp        0.000000 0.00000       
##  subid.1  pcorr0          0.005309 0.07286       
##           pcorr1          0.009288 0.09637  -1.00
##  subid.2  rGenHipp:pcorr0 0.027883 0.16698       
##           rGenHipp:pcorr1 0.034953 0.18696  1.00 
##  subid.3  (Intercept)     0.000000 0.00000       
##  Residual                 0.873476 0.93460       
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                          Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)             2.438e-02  1.280e-02  5.690e+02   1.905   0.0572
## group1                 -1.061e-02  1.280e-02  5.710e+02  -0.829   0.4073
## rGenHipp                2.660e-01  2.998e-02  3.900e+01   8.873 6.11e-11
## pcorr1                  9.584e-02  1.800e-02  4.300e+01   5.325 3.37e-06
## reps1                   4.938e-02  1.171e-02  6.576e+03   4.216 2.52e-05
## shockCond1             -3.824e-03  1.152e-02  6.561e+03  -0.332   0.7400
## rGenHipp:pcorr1        -1.621e-02  1.314e-02  7.710e+02  -1.234   0.2174
## group1:rGenHipp        -5.732e-02  2.998e-02  3.900e+01  -1.912   0.0632
## group1:pcorr1          -1.502e-02  1.789e-02  4.200e+01  -0.840   0.4059
## group1:rGenHipp:pcorr1 -1.542e-02  1.314e-02  7.710e+02  -1.174   0.2409
##                           
## (Intercept)            .  
## group1                    
## rGenHipp               ***
## pcorr1                 ***
## reps1                  ***
## shockCond1                
## rGenHipp:pcorr1           
## group1:rGenHipp        .  
## group1:pcorr1             
## group1:rGenHipp:pcorr1    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp pcorr1 reps1  shckC1 rGnH:1 gr1:GH grp1:1
## group1      -0.094                                                        
## rGenHipp    -0.015  0.020                                                 
## pcorr1       0.245 -0.147 -0.038                                          
## reps1       -0.024  0.030 -0.007 -0.107                                   
## shockCond1  -0.020  0.024  0.003 -0.006  0.003                            
## rGnHpp:pcr1 -0.159 -0.022  0.199 -0.020 -0.004 -0.005                     
## grp1:rGnHpp  0.021 -0.015 -0.065 -0.002 -0.009 -0.004 -0.100              
## grop1:pcrr1 -0.145  0.244 -0.003 -0.086 -0.004  0.000  0.034 -0.039       
## grp1:rGnH:1 -0.022 -0.160 -0.100  0.034 -0.006 -0.001 -0.107  0.199 -0.021

Mediation of hipp -> pcorr by VTC reinstatement

# run mediation if requested, otherwise just read in data already generated
if (run_mediation == TRUE){
  
  ## bootstrapping approach
  bootDist_0_hipp<-NULL
  bootDist_0_hippxgroup<-NULL
  bootDist_1_vtc<-NULL
  bootDist_1_vtcxgroup<-NULL
  bootDist_1_hipp<-NULL
  bootDist_1_hippxgroup<-NULL
  bootDist_2_hipp<-NULL
  bootDist_2_hippxgroup<-NULL
  min_persub <- NULL
  
  for (i in 1:5000) {
    print(i)
    # randomly sample from data, with replacement
    o1<-dCleanStandardized[sample(1:dim(dCleanStandardized)[1],
                                  size=dim(dCleanStandardized)[1],
                                  replace=T),]
    
    min_persub[i] = min(with(o1, table(subid))) # make sure sampling roughly equally across subs
    # all trials
    
    beq.0<-glmer(pcorr ~ group*(rGenHipp) + reps + shockCond +
                   (-1 + rGenHipp|subid) + 
                   (1|subid), 
                 data=o1, family = "binomial")
    
    bootDist_0_hipp[i]<-fixef(beq.0)[3] # overall effect of hipp
    bootDist_0_hippxgroup[i]<-fixef(beq.0)[6] # overall effect of hipp:group
    
    
    beq.1<-glmer(pcorr ~ group*(rGenHipp + ERActUnsigned) + reps + shockCond +
                   (-1 + rGenHipp|subid) + 
                   (-1 + ERActUnsigned|subid) + 
                   (1|subid), 
                 data=o1, family = "binomial")
    
    bootDist_1_vtc[i]<-fixef(beq.1)[4]
    bootDist_1_hipp[i]<-fixef(beq.1)[3]
    bootDist_1_hippxgroup[i]<-fixef(beq.1)[7]
    bootDist_1_vtcxgroup[i]<-fixef(beq.1)[8]
    
    beq.2<-lmer(ERActUnsigned ~ group*(rGenHipp) + reps + shockCond +  pcorr + 
                  (-1 + rGenHipp|subid)+
                  (1|subid), 
                data=o1)
    
    bootDist_2_hipp[i]<-fixef(beq.2)[3]
    bootDist_2_hippxgroup[i]<-fixef(beq.2)[7]
    
  }
  
  # Save out estimates
  boot_est = 
    data.frame(bootDist_0_hipp,
               bootDist_0_hippxgroup,
               bootDist_1_vtc,
               bootDist_1_vtcxgroup,
               bootDist_1_hipp,
               bootDist_1_hippxgroup,
               bootDist_2_hipp,
               bootDist_2_hippxgroup,
               min_persub)
  
  head(boot_est)
  dim(boot_est) # 5000x9
  # write.csv(boot_est, '~/Experiments/AP/stats/pcorr_hippxvtc_bootest.csv')
}

# read in estimates
boot_est = read.csv('~/Experiments/AP/stats/pcorr_hippxvtc_bootest.csv')
head(boot_est)
##   X bootDist_0_hipp bootDist_0_hippxgroup bootDist_1_vtc
## 1 1       0.3336975            0.03313248      0.3401121
## 2 2       0.3830903            0.07729301      0.2358331
## 3 3       0.3095557            0.10523026      0.2536265
## 4 4       0.3519444            0.11133494      0.2693219
## 5 5       0.3045465            0.12979939      0.2539781
## 6 6       0.3081529            0.12626098      0.3251825
##   bootDist_1_vtcxgroup bootDist_1_hipp bootDist_1_hippxgroup
## 1         -0.006185387       0.2442726            0.05085747
## 2         -0.028240283       0.3264301            0.10191093
## 3         -0.063827008       0.2495504            0.13205669
## 4         -0.026769713       0.2815676            0.13341756
## 5         -0.027122569       0.2404858            0.16146134
## 6         -0.017391119       0.2153574            0.16094638
##   bootDist_2_hipp bootDist_2_hippxgroup min_persub
## 1       0.2676985           -0.04757805        128
## 2       0.2597329           -0.06407083        112
## 3       0.2376320           -0.05350212        117
## 4       0.2719310           -0.07605860        124
## 5       0.2872711           -0.06754800        125
## 6       0.2602519           -0.04362020        121
dim(boot_est) # 5000x10
## [1] 5000   10
# overall effect
mean(boot_est$bootDist_0_hipp)
## [1] 0.3434265
quantile(boot_est$bootDist_0_hipp, c(.025, 0.975))
##      2.5%     97.5% 
## 0.2824646 0.4047669
mean(boot_est$bootDist_0_hippxgroup)
## [1] 0.09604791
quantile(boot_est$bootDist_0_hippxgroup, c(.025, 0.975))
##       2.5%      97.5% 
## 0.03602254 0.15561271
# direct effect
mean(boot_est$bootDist_1_hipp)
## [1] 0.2706472
quantile(boot_est$bootDist_1_hipp, c(.025, 0.975))
##      2.5%     97.5% 
## 0.2051427 0.3365692
mean(boot_est$bootDist_1_hippxgroup)
## [1] 0.1228647
quantile(boot_est$bootDist_1_hippxgroup, c(.025, 0.975))
##       2.5%      97.5% 
## 0.06020048 0.18672030
# a
mean(boot_est$bootDist_2_hipp)
## [1] 0.2648904
quantile(boot_est$bootDist_2_hipp,c(.025, 0.975))
##      2.5%     97.5% 
## 0.2411793 0.2883050
mean(boot_est$bootDist_2_hippxgroup)
## [1] -0.06000476
quantile(boot_est$bootDist_2_hippxgroup,c(.025, 0.975))
##        2.5%       97.5% 
## -0.08402030 -0.03689056
# b
mean(boot_est$bootDist_1_vtc)
## [1] 0.2735032
quantile(boot_est$bootDist_1_vtc, c(.025, 0.975))
##      2.5%     97.5% 
## 0.2086499 0.3356519
mean(boot_est$bootDist_1_vtcxgroup)
## [1] -0.03461619
quantile(boot_est$bootDist_1_vtcxgroup, c(.025, 0.975))
##        2.5%       97.5% 
## -0.09665609  0.02888107
# mediation
IE_hippVIAvtc = boot_est$bootDist_1_vtc * boot_est$bootDist_2_hipp
hist(IE_hippVIAvtc)

mean(IE_hippVIAvtc)
## [1] 0.07239975
quantile(IE_hippVIAvtc,c(.025, 0.975))
##       2.5%      97.5% 
## 0.05520369 0.08977096

Plots:

pSourcehit ~ hipp BOLD

## Automatically converting the following non-factors to factors: hipp_quintile
##      group hipp_quintile   reps  N     pcorr pcorr_norm         sd
## 1  control             1   weak 22 0.3100913  0.2232141 0.14546483
## 2  control             1 strong 22 0.4742126  0.3873354 0.10106810
## 3  control             2   weak 22 0.3696009  0.2827238 0.11914158
## 4  control             2 strong 22 0.5490386  0.4621614 0.10590166
## 5  control             3   weak 22 0.4173077  0.3304305 0.10339345
## 6  control             3 strong 22 0.5611449  0.4742677 0.12174464
## 7  control             4   weak 22 0.4820399  0.3951627 0.13175145
## 8  control             4 strong 22 0.6357036  0.5488264 0.08697430
## 9  control             5   weak 22 0.5660647  0.4791875 0.14129631
## 10 control             5 strong 22 0.7093450  0.6224678 0.13309681
## 11  stress             1   weak 20 0.1920822  0.2876471 0.14054417
## 12  stress             1 strong 20 0.3288506  0.4244155 0.11218147
## 13  stress             2   weak 20 0.2674672  0.3630321 0.14702833
## 14  stress             2 strong 20 0.3458826  0.4414475 0.12028195
## 15  stress             3   weak 20 0.2658584  0.3614233 0.09625913
## 16  stress             3 strong 20 0.4234249  0.5189898 0.12230139
## 17  stress             4   weak 20 0.2791886  0.3747535 0.12723380
## 18  stress             4 strong 20 0.4375441  0.5331090 0.15923483
## 19  stress             5   weak 20 0.2869778  0.3825427 0.12177475
## 20  stress             5 strong 20 0.4228520  0.5184169 0.12610978
##            se         ci
## 1  0.03101321 0.06449549
## 2  0.02154779 0.04481109
## 3  0.02540107 0.05282442
## 4  0.02257831 0.04695416
## 5  0.02204356 0.04584209
## 6  0.02595604 0.05397855
## 7  0.02808950 0.05841532
## 8  0.01854298 0.03856225
## 9  0.03012447 0.06264727
## 10 0.02837634 0.05901182
## 11 0.03142663 0.06577670
## 12 0.02508454 0.05250254
## 13 0.03287653 0.06881138
## 14 0.02689586 0.05629369
## 15 0.02152420 0.04505066
## 16 0.02734742 0.05723881
## 17 0.02845034 0.05954725
## 18 0.03560599 0.07452419
## 19 0.02722966 0.05699234
## 20 0.02819900 0.05902119

## Automatically converting the following non-factors to factors: hipp_quintile
##      group hipp_quintile  N     pcorr pcorr_norm         sd         se
## 1  control             1 22 0.3921519  0.3052748 0.10612646 0.02262624
## 2  control             2 22 0.4593198  0.3724426 0.07173378 0.01529369
## 3  control             3 22 0.4892263  0.4023491 0.06871020 0.01464906
## 4  control             4 22 0.5588718  0.4719946 0.08105797 0.01728162
## 5  control             5 22 0.6377048  0.5508277 0.11896710 0.02536387
## 6   stress             1 20 0.2604664  0.3560313 0.10024634 0.02241576
## 7   stress             2 20 0.3066749  0.4022398 0.10647378 0.02380826
## 8   stress             3 20 0.3446416  0.4402065 0.07146471 0.01597999
## 9   stress             4 20 0.3583664  0.4539313 0.09708466 0.02170879
## 10  stress             5 20 0.3549149  0.4504798 0.10223849 0.02286122
##            ci
## 1  0.04705384
## 2  0.03180498
## 3  0.03046440
## 4  0.03593909
## 5  0.05274706
## 6  0.04691673
## 7  0.04983127
## 8  0.03344651
## 9  0.04543702
## 10 0.04784909

Plot prop trials/cond by hipp quintile

old_counts = dm %>% 
  group_by(subid, group, hipp_quintile) %>%
  summarise(old_count = n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), hipp_quintile, fill = list(old_count=0))

d_counts = dm %>% 
  group_by(subid, group, cond, hipp_quintile) %>%
  summarise(count = n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), cond, hipp_quintile, fill = list(count=0))

d_avg = d_counts %>% left_join(old_counts) %>% 
  mutate(prop = count/old_count)
## Joining, by = c("subid", "group", "hipp_quintile")
d_avg
## # A tibble: 840 x 7
##     subid   group       cond hipp_quintile count old_count       prop
##    <fctr>  <fctr>     <fctr>         <int> <dbl>     <dbl>      <dbl>
##  1  ap100 control itemhit_lo             1     6        31 0.19354839
##  2  ap100 control itemhit_lo             2     5        31 0.16129032
##  3  ap100 control itemhit_lo             3     6        31 0.19354839
##  4  ap100 control itemhit_lo             4     6        31 0.19354839
##  5  ap100 control itemhit_lo             5     2        30 0.06666667
##  6  ap100 control          M             1     6        31 0.19354839
##  7  ap100 control          M             2     7        31 0.22580645
##  8  ap100 control          M             3     6        31 0.19354839
##  9  ap100 control          M             4     5        31 0.16129032
## 10  ap100 control          M             5     6        30 0.20000000
## # ... with 830 more rows
dfwc = summarySEwithin(d_avg, measurevar="prop", withinvars=c("hipp_quintile",
                                                              "cond"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: hipp_quintile
dfwc
##      group hipp_quintile          cond  N       prop  prop_norm         sd
## 1  control             1    itemhit_lo 22 0.35276098 0.35276098 0.21186145
## 2  control             1             M 22 0.16431512 0.16431512 0.10388456
## 3  control             1     sourcehit 22 0.38426134 0.38426134 0.20434658
## 4  control             1 sourcemiss_hi 22 0.09866256 0.09866256 0.07197340
## 5  control             2    itemhit_lo 22 0.34139656 0.34139656 0.22308178
## 6  control             2             M 22 0.11880994 0.11880994 0.08109151
## 7  control             2     sourcehit 22 0.44540642 0.44540642 0.23806021
## 8  control             2 sourcemiss_hi 22 0.09438709 0.09438709 0.09311189
## 9  control             3    itemhit_lo 22 0.30301830 0.30301830 0.19837352
## 10 control             3             M 22 0.11717737 0.11717737 0.09854851
## 11 control             3     sourcehit 22 0.48988295 0.48988295 0.25286916
## 12 control             3 sourcemiss_hi 22 0.08992137 0.08992137 0.05523477
## 13 control             4    itemhit_lo 22 0.25178994 0.25178994 0.20635251
## 14 control             4             M 22 0.11247039 0.11247039 0.10665321
## 15 control             4     sourcehit 22 0.55953570 0.55953570 0.26064033
## 16 control             4 sourcemiss_hi 22 0.07620396 0.07620396 0.04890686
## 17 control             5    itemhit_lo 22 0.20133982 0.20133982 0.23565830
## 18 control             5             M 22 0.06469735 0.06469735 0.08056454
## 19 control             5     sourcehit 22 0.64590501 0.64590501 0.28732515
## 20 control             5 sourcemiss_hi 22 0.08805782 0.08805782 0.08559806
## 21  stress             1    itemhit_lo 20 0.46099172 0.46099172 0.22253005
## 22  stress             1             M 20 0.20785387 0.20785387 0.18838795
## 23  stress             1     sourcehit 20 0.25600609 0.25600609 0.16566487
## 24  stress             1 sourcemiss_hi 20 0.07514832 0.07514832 0.05903036
## 25  stress             2    itemhit_lo 20 0.40819940 0.40819940 0.20386214
## 26  stress             2             M 20 0.19139423 0.19139423 0.12983854
## 27  stress             2     sourcehit 20 0.30132944 0.30132944 0.14377106
## 28  stress             2 sourcemiss_hi 20 0.09907693 0.09907693 0.07491831
## 29  stress             3    itemhit_lo 20 0.38554256 0.38554256 0.22360851
## 30  stress             3             M 20 0.19122182 0.19122182 0.14239897
## 31  stress             3     sourcehit 20 0.34325649 0.34325649 0.17978893
## 32  stress             3 sourcemiss_hi 20 0.07997913 0.07997913 0.06869600
## 33  stress             4    itemhit_lo 20 0.33727768 0.33727768 0.17289819
## 34  stress             4             M 20 0.19303524 0.19303524 0.16082421
## 35  stress             4     sourcehit 20 0.36347673 0.36347673 0.18176464
## 36  stress             4 sourcemiss_hi 20 0.10621035 0.10621035 0.07378585
## 37  stress             5    itemhit_lo 20 0.39068835 0.39068835 0.23510317
## 38  stress             5             M 20 0.16467990 0.16467990 0.16850700
## 39  stress             5     sourcehit 20 0.36220528 0.36220528 0.20178193
## 40  stress             5 sourcemiss_hi 20 0.08242646 0.08242646 0.07544436
##            se         ci
## 1  0.04516901 0.09393410
## 2  0.02214826 0.04605984
## 3  0.04356684 0.09060220
## 4  0.01534478 0.03191122
## 5  0.04756120 0.09890892
## 6  0.01728877 0.03595396
## 7  0.05075461 0.10554998
## 8  0.01985152 0.04128350
## 9  0.04229338 0.08795389
## 10 0.02101061 0.04369396
## 11 0.05391189 0.11211590
## 12 0.01177609 0.02448972
## 13 0.04399450 0.09149158
## 14 0.02273854 0.04728738
## 15 0.05556870 0.11556145
## 16 0.01042698 0.02168409
## 17 0.05024252 0.10448504
## 18 0.01717642 0.03572032
## 19 0.06125793 0.12739283
## 20 0.01824957 0.03795205
## 21 0.04975923 0.10414727
## 22 0.04212483 0.08816828
## 23 0.03704379 0.07753354
## 24 0.01319959 0.02762706
## 25 0.04558496 0.09541042
## 26 0.02903278 0.06076631
## 27 0.03214819 0.06728693
## 28 0.01675224 0.03506285
## 29 0.05000038 0.10465200
## 30 0.03184138 0.06664477
## 31 0.04020203 0.08414381
## 32 0.01536089 0.03215072
## 33 0.03866121 0.08091884
## 34 0.03596139 0.07526805
## 35 0.04064381 0.08506847
## 36 0.01649902 0.03453284
## 37 0.05257067 0.11003167
## 38 0.03767931 0.07886370
## 39 0.04511981 0.09443685
## 40 0.01686987 0.03530905
p2 = ggplot(dfwc, aes(x=hipp_quintile, y=prop, group=cond, color=cond)) +
    facet_grid(.~group)+
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=prop-se, 
                               ymax=prop+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  xlab('Hippocampal activity (quintiles)')+
  ylab('p Old trials')+
  scale_color_brewer(palette = 'Set1', guide = guide_legend(title = NULL))

ggsave(p2, 
       filename ='~/Experiments/AP/figs/pOLDXhippxreps_quintile_allOLD_wholehipp.jpg', 
       dpi=150, width = 8, height=4.4)
p2

Plot prop trials/cond by VTC quintile

old_counts = dm %>% 
  group_by(subid, group, vtc_quintile) %>%
  summarise(old_count = n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), vtc_quintile, fill = list(old_count=0))

d_counts = dm %>% 
  group_by(subid, group, cond, vtc_quintile) %>%
  summarise(count = n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), cond, vtc_quintile, fill = list(count=0))

d_avg = d_counts %>% left_join(old_counts) %>% 
  mutate(prop = count/old_count)
## Joining, by = c("subid", "group", "vtc_quintile")
d_avg
## # A tibble: 840 x 7
##     subid   group       cond vtc_quintile count old_count       prop
##    <fctr>  <fctr>     <fctr>        <int> <dbl>     <dbl>      <dbl>
##  1  ap100 control itemhit_lo            1     6        31 0.19354839
##  2  ap100 control itemhit_lo            2     3        31 0.09677419
##  3  ap100 control itemhit_lo            3     6        31 0.19354839
##  4  ap100 control itemhit_lo            4     4        31 0.12903226
##  5  ap100 control itemhit_lo            5     6        30 0.20000000
##  6  ap100 control          M            1    13        31 0.41935484
##  7  ap100 control          M            2     6        31 0.19354839
##  8  ap100 control          M            3     4        31 0.12903226
##  9  ap100 control          M            4     3        31 0.09677419
## 10  ap100 control          M            5     4        30 0.13333333
## # ... with 830 more rows
dfwc = summarySEwithin(d_avg, measurevar="prop", withinvars=c("vtc_quintile",
                                                              "cond"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: vtc_quintile
dfwc
##      group vtc_quintile          cond  N       prop  prop_norm         sd
## 1  control            1    itemhit_lo 22 0.34331686 0.34331686 0.19483767
## 2  control            1             M 22 0.23403553 0.23403553 0.13586695
## 3  control            1     sourcehit 22 0.36563626 0.36563626 0.24880531
## 4  control            1 sourcemiss_hi 22 0.05701135 0.05701135 0.06365228
## 5  control            2    itemhit_lo 22 0.28590814 0.28590814 0.21630470
## 6  control            2             M 22 0.13556170 0.13556170 0.10767858
## 7  control            2     sourcehit 22 0.51957945 0.51957945 0.25747819
## 8  control            2 sourcemiss_hi 22 0.05895071 0.05895071 0.05719109
## 9  control            3    itemhit_lo 22 0.30673921 0.30673921 0.23504879
## 10 control            3             M 22 0.09083906 0.09083906 0.07779137
## 11 control            3     sourcehit 22 0.52350159 0.52350159 0.28035662
## 12 control            3 sourcemiss_hi 22 0.07892014 0.07892014 0.05765584
## 13 control            4    itemhit_lo 22 0.29598970 0.29598970 0.21992697
## 14 control            4             M 22 0.07073550 0.07073550 0.06627701
## 15 control            4     sourcehit 22 0.53870328 0.53870328 0.25128105
## 16 control            4 sourcemiss_hi 22 0.09457152 0.09457152 0.07711294
## 17 control            5    itemhit_lo 22 0.21835402 0.21835402 0.21698316
## 18 control            5             M 22 0.04497705 0.04497705 0.06089267
## 19 control            5     sourcehit 22 0.57749583 0.57749583 0.20780342
## 20 control            5 sourcemiss_hi 22 0.15917310 0.15917310 0.10879425
## 21  stress            1    itemhit_lo 20 0.40488787 0.40488787 0.21068485
## 22  stress            1             M 20 0.29705376 0.29705376 0.18815374
## 23  stress            1     sourcehit 20 0.21504414 0.21504414 0.13838350
## 24  stress            1 sourcemiss_hi 20 0.08301424 0.08301424 0.07430011
## 25  stress            2    itemhit_lo 20 0.43379585 0.43379585 0.21568944
## 26  stress            2             M 20 0.19439869 0.19439869 0.15149622
## 27  stress            2     sourcehit 20 0.30783653 0.30783653 0.18983027
## 28  stress            2 sourcemiss_hi 20 0.06396894 0.06396894 0.05926241
## 29  stress            3    itemhit_lo 20 0.40157376 0.40157376 0.21571099
## 30  stress            3             M 20 0.19380016 0.19380016 0.18209700
## 31  stress            3     sourcehit 20 0.32327140 0.32327140 0.14879653
## 32  stress            3 sourcemiss_hi 20 0.08135468 0.08135468 0.05823998
## 33  stress            4    itemhit_lo 20 0.39428115 0.39428115 0.21296860
## 34  stress            4             M 20 0.14986543 0.14986543 0.13959832
## 35  stress            4     sourcehit 20 0.35673821 0.35673821 0.18502669
## 36  stress            4 sourcemiss_hi 20 0.09911521 0.09911521 0.08466166
## 37  stress            5    itemhit_lo 20 0.34917543 0.34917543 0.20832641
## 38  stress            5             M 20 0.11108045 0.11108045 0.14443430
## 39  stress            5     sourcehit 20 0.42471654 0.42471654 0.20082490
## 40  stress            5 sourcemiss_hi 20 0.11502758 0.11502758 0.08851722
##            se         ci
## 1  0.04153953 0.08638618
## 2  0.02896693 0.06024003
## 3  0.05304547 0.11031410
## 4  0.01357071 0.02822184
## 5  0.04611632 0.09590413
## 6  0.02295715 0.04774201
## 7  0.05489454 0.11415944
## 8  0.01219318 0.02535711
## 9  0.05011257 0.10421479
## 10 0.01658518 0.03449076
## 11 0.05977223 0.12430316
## 12 0.01229227 0.02556317
## 13 0.04688859 0.09751015
## 14 0.01413031 0.02938558
## 15 0.05357330 0.11141178
## 16 0.01644053 0.03418996
## 17 0.04626096 0.09620494
## 18 0.01298236 0.02699830
## 19 0.04430384 0.09213488
## 20 0.02319501 0.04823667
## 21 0.04711056 0.09860354
## 22 0.04207246 0.08805866
## 23 0.03094349 0.06476547
## 24 0.01661401 0.03477352
## 25 0.04822962 0.10094576
## 26 0.03387558 0.07090241
## 27 0.04244734 0.08884330
## 28 0.01325148 0.02773566
## 29 0.04823444 0.10095585
## 30 0.04071813 0.08522402
## 31 0.03327192 0.06963892
## 32 0.01302286 0.02725715
## 33 0.04762123 0.09967237
## 34 0.03121513 0.06533403
## 35 0.04137323 0.08659516
## 36 0.01893092 0.03962288
## 37 0.04658320 0.09749976
## 38 0.03229649 0.06759733
## 39 0.04490581 0.09398895
## 40 0.01979305 0.04142734
p2 = ggplot(dfwc, aes(x=vtc_quintile, y=prop, group=cond, color=cond)) +
    facet_grid(.~group)+
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=prop-se, 
                               ymax=prop+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  xlab('Reinstatement strength (quintiles)')+
  ylab('p Old trials')+
  scale_color_brewer(palette = 'Set1', guide = guide_legend(title = NULL))

ggsave(p2, 
       filename ='~/Experiments/AP/figs/pOLDXvtc_quintile_allOLD_wholehipp.jpg', 
       dpi=150, width = 8, height=4.4)
p2

z-scored hipp by condition

d_avg = dm %>% 
  group_by(subid, group, cond) %>%
  summarise(hipp_sig_z = mean(hipp_sig_z))
d_avg
## Source: local data frame [167 x 4]
## Groups: subid, group [?]
## 
## # A tibble: 167 x 4
##     subid   group          cond  hipp_sig_z
##    <fctr>  <fctr>        <fctr>       <dbl>
##  1  ap100 control    itemhit_lo -0.22153305
##  2  ap100 control             M -0.08858725
##  3  ap100 control     sourcehit  0.11669585
##  4  ap100 control sourcemiss_hi -0.16304960
##  5  ap101 control    itemhit_lo -0.49336910
##  6  ap101 control             M -0.61006589
##  7  ap101 control     sourcehit  0.29371383
##  8  ap101 control sourcemiss_hi  0.25060666
##  9  ap102 control    itemhit_lo -0.29776794
## 10  ap102 control             M -0.05133410
## # ... with 157 more rows
dfwc = summarySEwithin(d_avg, measurevar="hipp_sig_z", withinvars=c("cond"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
dfwc
##     group          cond  N   hipp_sig_z hipp_sig_z_norm        sd
## 1 control    itemhit_lo 21 -0.245061388     -0.19636229 0.2544894
## 2 control             M 22 -0.355365623     -0.29596648 0.2065093
## 3 control     sourcehit 22  0.167099187      0.22649833 0.3044788
## 4 control sourcemiss_hi 22  0.010926767      0.07032591 0.4464622
## 5  stress    itemhit_lo 20  0.001801552     -0.05998625 0.3932803
## 6  stress             M 20 -0.112207534     -0.17399534 0.2557633
## 7  stress     sourcehit 20  0.153534276      0.09174647 0.2900263
## 8  stress sourcemiss_hi 20  0.015299366     -0.04648844 0.2960797
##           se         ci
## 1 0.05553415 0.11584220
## 2 0.04402792 0.09156108
## 3 0.06491510 0.13499835
## 4 0.09518606 0.19795025
## 5 0.08794015 0.18406086
## 6 0.05719041 0.11970090
## 7 0.06485185 0.13573648
## 8 0.06620544 0.13856959
p2 = ggplot(dfwc, aes(x=cond, y=hipp_sig_z, group=group, color=group)) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=hipp_sig_z-se, 
                               ymax=hipp_sig_z+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  xlab('condition')+
  ylab('Hippocampal signal\n(z-scored)')+
  scale_color_manual(values = palette, guide = guide_legend(title = NULL))
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/hippsigzxcond_allOLD_wholehipp.jpg',
       dpi=150, width = 8, height=4.4)
p2

pSourcehit ~ VTC

## Automatically converting the following non-factors to factors: vtc_quintile
##      group vtc_quintile   reps  N     pcorr pcorr_norm         sd
## 1  control            1   weak 22 0.2762090  0.1890566 0.17157145
## 2  control            1 strong 22 0.4904741  0.4033218 0.17586139
## 3  control            2   weak 22 0.4228444  0.3356921 0.10603623
## 4  control            2 strong 22 0.6190047  0.5318524 0.12346851
## 5  control            3   weak 22 0.4418255  0.3546731 0.08492566
## 6  control            3 strong 22 0.6196368  0.5324844 0.12585047
## 7  control            4   weak 22 0.4758510  0.3886986 0.11445124
## 8  control            4 strong 22 0.5938993  0.5067469 0.10544557
## 9  control            5   weak 22 0.4933183  0.4061659 0.13056869
## 10 control            5 strong 22 0.6443695  0.5572171 0.17127927
## 11  stress            1   weak 20 0.1541300  0.2499976 0.13475615
## 12  stress            1 strong 20 0.2882107  0.3840783 0.12691446
## 13  stress            2   weak 20 0.2374587  0.3333263 0.11581727
## 14  stress            2 strong 20 0.3802869  0.4761545 0.12746713
## 15  stress            3   weak 20 0.2796452  0.3755128 0.12450140
## 16  stress            3 strong 20 0.3757698  0.4716374 0.11602903
## 17  stress            4   weak 20 0.3031382  0.3990058 0.11581835
## 18  stress            4 strong 20 0.4125594  0.5084270 0.10881162
## 19  stress            5   weak 20 0.3226128  0.4184804 0.12802254
## 20  stress            5 strong 20 0.4934211  0.5892888 0.13998358
##            se         ci
## 1  0.03657916 0.07607052
## 2  0.03749377 0.07797257
## 3  0.02260700 0.04701383
## 4  0.02632357 0.05474287
## 5  0.01810621 0.03765393
## 6  0.02683141 0.05579897
## 7  0.02440109 0.05074484
## 8  0.02248107 0.04675195
## 9  0.02783734 0.05789091
## 10 0.03651686 0.07594097
## 11 0.03013239 0.06306782
## 12 0.02837894 0.05939779
## 13 0.02589753 0.05420415
## 14 0.02850252 0.05965645
## 15 0.02783936 0.05826845
## 16 0.02594488 0.05430326
## 17 0.02589777 0.05420466
## 18 0.02433102 0.05092541
## 19 0.02862671 0.05991640
## 20 0.03130128 0.06551433

## Automatically converting the following non-factors to factors: vtc_quintile
##      group vtc_quintile  N     pcorr pcorr_norm         sd         se
## 1  control            1 22 0.3833416  0.2961892 0.11926155 0.02542665
## 2  control            2 22 0.5209246  0.4337722 0.08492980 0.01810709
## 3  control            3 22 0.5307311  0.4435788 0.08382327 0.01787118
## 4  control            4 22 0.5348751  0.4477227 0.07459251 0.01590318
## 5  control            5 22 0.5688439  0.4816915 0.12504708 0.02666013
## 6   stress            1 20 0.2211704  0.3170380 0.11358762 0.02539896
## 7   stress            2 20 0.3088728  0.4047404 0.10959979 0.02450726
## 8   stress            3 20 0.3277075  0.4235751 0.07874369 0.01760762
## 9   stress            4 20 0.3578488  0.4537164 0.07454267 0.01666825
## 10  stress            5 20 0.4080170  0.5038846 0.10545304 0.02358002
##            ci
## 1  0.05287761
## 2  0.03765577
## 3  0.03716516
## 4  0.03307247
## 5  0.05544277
## 6  0.05316064
## 7  0.05129428
## 8  0.03685318
## 9  0.03488704
## 10 0.04935354

VTC ~ hipp BOLD

dm_avg = dm %>%
  group_by(subid, group, hipp_quintile, reps) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n()) 

dim(dm_avg)
## [1] 420   6
dfwc = summarySEwithin(dm_avg, measurevar="vtc_logit", 
                       withinvars=c("hipp_quintile", "reps"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95) %>% 
  mutate(reps=ifelse(reps == "4", "strong", "weak"),
         reps=factor(reps, levels=c('weak', 'strong')))
## Automatically converting the following non-factors to factors: hipp_quintile
dfwc
##      group hipp_quintile   reps  N   vtc_logit vtc_logit_norm        sd
## 1  control             1   weak 22 -0.74440752    -0.90008242 1.0908007
## 2  control             1 strong 22 -0.28463077    -0.44030568 1.2030404
## 3  control             2   weak 22 -0.08859177    -0.24426667 0.9251402
## 4  control             2 strong 22  0.45782397     0.30214907 0.7824452
## 5  control             3   weak 22  0.20458897     0.04891407 0.7935526
## 6  control             3 strong 22  0.63050493     0.47483003 0.7368128
## 7  control             4   weak 22  0.76720258     0.61152767 0.9012212
## 8  control             4 strong 22  0.80915512     0.65348022 0.6356722
## 9  control             5   weak 22  1.37357101     1.21789610 0.8363582
## 10 control             5 strong 22  1.24771890     1.09204400 1.1796830
## 11  stress             1   weak 20 -1.31163457    -1.14039218 1.0981805
## 12  stress             1 strong 20 -0.98405795    -0.81281555 1.0673480
## 13  stress             2   weak 20 -0.63686645    -0.46562405 0.6786301
## 14  stress             2 strong 20 -0.25150904    -0.08026664 0.6901484
## 15  stress             3   weak 20 -0.12550461     0.04573778 0.7387358
## 16  stress             3 strong 20  0.28418265     0.45542505 0.8139988
## 17  stress             4   weak 20  0.40468520     0.57592760 0.7157759
## 18  stress             4 strong 20  0.83189612     1.00313851 1.0003450
## 19  stress             5   weak 20  1.22920014     1.40044253 1.0198885
## 20  stress             5 strong 20  1.66337095     1.83461335 1.2142923
##           se        ci
## 1  0.2325595 0.4836339
## 2  0.2564891 0.5333982
## 3  0.1972406 0.4101842
## 4  0.1668179 0.3469168
## 5  0.1691860 0.3518415
## 6  0.1570890 0.3266845
## 7  0.1921410 0.3995791
## 8  0.1355258 0.2818413
## 9  0.1783122 0.3708205
## 10 0.2515093 0.5230422
## 11 0.2455606 0.5139643
## 12 0.2386663 0.4995343
## 13 0.1517463 0.3176087
## 14 0.1543219 0.3229994
## 15 0.1651863 0.3457390
## 16 0.1820157 0.3809632
## 17 0.1600524 0.3349934
## 18 0.2236839 0.4681759
## 19 0.2280540 0.4773225
## 20 0.2715240 0.5683063
p2 = ggplot(dfwc, aes(x=hipp_quintile, y=vtc_logit, group=group, color=group)) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=vtc_logit-se, 
                               ymax=vtc_logit+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  facet_grid(. ~ reps) +
  ylab('Reinstatement strength (logits)')+
  xlab('Hippocampal activity (quintiles)')+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p2

ggsave(p2, 
       filename ='~/Experiments/AP/figs/logitXhippxreps_quintile_allOLD_wholehipp.jpg', 
       dpi=150, width = 8, height=4.4)
p2

## collapse across rep
dm_avg = dm %>%
  group_by(subid, group, hipp_quintile, reps) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n()) %>%
  group_by(subid, group, hipp_quintile) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n()) 

dfwc = summarySEwithin(dm_avg, measurevar="vtc_logit", 
                       withinvars=c("hipp_quintile"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: hipp_quintile
dfwc
##      group hipp_quintile  N   vtc_logit vtc_logit_norm        sd
## 1  control             1 22 -0.51451915     -0.6701941 1.0612817
## 2  control             2 22  0.18461610      0.0289412 0.7474041
## 3  control             3 22  0.41754695      0.2618720 0.5459523
## 4  control             4 22  0.78817885      0.6325039 0.6302229
## 5  control             5 22  1.31064496      1.1549701 0.9216787
## 6   stress             1 20 -1.14784626     -0.9766039 0.9643338
## 7   stress             2 20 -0.44418774     -0.2729453 0.5264578
## 8   stress             3 20  0.07933902      0.2505814 0.3588214
## 9   stress             4 20  0.61829066      0.7895331 0.5503767
## 10  stress             5 20  1.44628554      1.6175279 1.0794175
##            se        ci
## 1  0.22626603 0.4705460
## 2  0.15934710 0.3313804
## 3  0.11639743 0.2420617
## 4  0.13436398 0.2794252
## 5  0.19650255 0.4086494
## 6  0.21563160 0.4513221
## 7  0.11771953 0.2463898
## 8  0.08023491 0.1679336
## 9  0.12306797 0.2575842
## 10 0.24136509 0.5051829
p2 = ggplot(dfwc, aes(x=hipp_quintile, y=vtc_logit, group=group, color=group)) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=vtc_logit-se, 
                               ymax=vtc_logit+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('Reinstatement strength')+
  xlab('Hippocampal activity (quintiles)')+
  scale_color_manual(values=palette, 
                     guide = guide_legend(title = NULL))+
  theme_classic(base_size = 20)+
  theme(legend.title=element_blank(), 
        legend.position="none",
        strip.background = element_rect(colour="white", fill="white"))
p2

ggsave(p2, 
       filename ='~/Experiments/AP/figs/logitXhipp_quintile_allOLD_wholehipp.jpg', 
       dpi=600, width = 4.65, height=4)
p2

## logits (z-scored within subj)
dm_avg = dm %>%
  group_by(subid, group, hipp_quintile, reps) %>%
  summarise(vtc_logit = mean_(vtc_logit_z), count = n()) %>%
  group_by(subid, group, hipp_quintile) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n()) 

dfwc = summarySEwithin(dm_avg, measurevar="vtc_logit", withinvars=c("hipp_quintile"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: hipp_quintile
dfwc
##      group hipp_quintile  N    vtc_logit vtc_logit_norm        sd
## 1  control             1 22 -0.309268431   -0.310953910 0.3425772
## 2  control             2 22 -0.077340217   -0.079025696 0.2556196
## 3  control             3 22 -0.006171192   -0.007856671 0.1767599
## 4  control             4 22  0.112310524    0.110625044 0.2044810
## 5  control             5 22  0.296760225    0.295074746 0.2839917
## 6   stress             1 20 -0.432574439   -0.430720412 0.3183049
## 7   stress             2 20 -0.193565564   -0.191711536 0.1674465
## 8   stress             3 20 -0.014512115   -0.012658088 0.1287906
## 9   stress             4 20  0.179418496    0.181272524 0.1782260
## 10  stress             5 20  0.459826998    0.461681026 0.3452719
##            se         ci
## 1  0.07303769 0.15189020
## 2  0.05449829 0.11333539
## 3  0.03768533 0.07837093
## 4  0.04359550 0.09066181
## 5  0.06054723 0.12591486
## 6  0.07117514 0.14897128
## 7  0.03744217 0.07836736
## 8  0.02879845 0.06027585
## 9  0.03985255 0.08341234
## 10 0.07720514 0.16159222
p2 = ggplot(dfwc, aes(x=hipp_quintile, y=vtc_logit, group=group, color=group)) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=vtc_logit-se, 
                               ymax=vtc_logit+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('Reinstatement strength\n(z-scored logits)')+
  xlab('Hippocampal activity (quintiles)')+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p2

ggsave(p2, 
       filename ='~/Experiments/AP/figs/zscoredlogitXhipp_quintile_allOLD_wholehipp.jpg', 
       dpi=150, width = 6, height=4)
p2

Look at hipp raw timecourse across all old trials

# Read in hipp BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-hippocampus.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-hippocampus.csv')

# Take timepoints of interest for old trials, and collapse across hemispheres
roi_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M')) %>%
  group_by(subid, hemi, run, onset, time) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset, time) %>%
  summarise(hipp_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
roi_f = roi_f %>% inner_join(d, by=c('subid', 'run', 'onset')) %>%
   mutate(subid = factor(subid),
         cond = factor(cond)) %>%
  left_join(dm %>% dplyr::select(subid, run, onset, hipp_quintile))
## Warning in inner_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
## Joining, by = c("subid", "run", "onset")
roi_f %>% group_by(group, subid) %>% summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    20
head(roi_f)
## # A tibble: 6 x 53
##    subid   run  onset  time    hipp_sig   X.x trial duration shockCond
##   <fctr> <dbl>  <dbl> <int>       <dbl> <int> <int>    <dbl>    <fctr>
## 1  ap100     1 0.0191     0 -0.25848007     0     1  10.6661      safe
## 2  ap100     1 0.0191     2 -0.29558563     0     1  10.6661      safe
## 3  ap100     1 0.0191     4  0.06634903     0     1  10.6661      safe
## 4  ap100     1 0.0191     6  0.38894272     0     1  10.6661      safe
## 5  ap100     1 0.0191     8  0.60944748     0     1  10.6661      safe
## 6  ap100     1 0.0191    10  0.03682709     0     1  10.6661      safe
## # ... with 44 more variables: shockTrial <int>, target <fctr>,
## #   associate <fctr>, resp <fctr>, acc <fctr>, accSpec <fctr>,
## #   respRT <dbl>, remove <lgl>, anxious <int>, happy <int>, safe <int>,
## #   stressed <int>, life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <int>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_quintile <int>
with(roi_f, table(cond, condition))
##                condition
## cond             CR-0  FA-0 itemhit_lo-2 itemhit_lo-4   M-2   M-4
##   itemhit_lo        0     0         8862         6930     0     0
##   M                 0     0            0            0  4424  2471
##   sourcehit         0     0            0            0     0     0
##   sourcemiss_hi     0     0            0            0     0     0
##                condition
## cond            sourcehit-2 sourcehit-4 sourcemiss_hi-2 sourcemiss_hi-4
##   itemhit_lo              0           0               0               0
##   M                       0           0               0               0
##   sourcehit            7924       11655               0               0
##   sourcemiss_hi           0           0            1946            2149
ggplot(roi_f %>% group_by(subid, cond, time) %>% 
         summarise(hipp_sig = mean(hipp_sig)) %>% 
         group_by(time, cond) %>% 
         summarise(mean(hipp_sig)), 
       aes(x=time, y=`mean(hipp_sig)`, color=cond, group=cond)) +
  geom_line()

Break down by quintile (from above plotting)
hipp_avg = roi_f %>% 
  group_by(subid, group, hipp_quintile, time) %>% 
  summarise(hipp_sig = mean(hipp_sig)) %>%
  group_by(group, hipp_quintile, time) %>%
  summarise(mean = mean(hipp_sig), se = std.error(hipp_sig), n())
hipp_avg  
## Source: local data frame [70 x 6]
## Groups: group, hipp_quintile [?]
## 
## # A tibble: 70 x 6
##      group hipp_quintile  time        mean         se `n()`
##     <fctr>         <int> <int>       <dbl>      <dbl> <int>
##  1 control             1     0 -0.09739443 0.02388204    22
##  2 control             1     2 -0.21292476 0.02862795    22
##  3 control             1     4 -0.35297557 0.02968476    22
##  4 control             1     6 -0.40003707 0.02731876    22
##  5 control             1     8 -0.38541653 0.02467327    22
##  6 control             1    10 -0.33272448 0.02171856    22
##  7 control             1    12 -0.23328205 0.02678441    22
##  8 control             2     0 -0.01681712 0.01663057    22
##  9 control             2     2 -0.08682270 0.01654324    22
## 10 control             2     4 -0.11314266 0.01639213    22
## # ... with 60 more rows
blues <- brewer.pal(6, "Blues")[2:6]
p2 = ggplot(hipp_avg, aes(x=factor(time), y=mean, group=factor(hipp_quintile), color=factor(hipp_quintile))) +
    facet_grid(.~group) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=mean-se, 
                               ymax=mean+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('% signal change') +
  xlab('Time post-stimulus onset (s)') +
  guides(color=guide_legend(title="Quintile")) +
  scale_color_manual(values=blues)
ggsave(p2,
       filename ='~/Experiments/AP/figs/hipp_bytimeXhippQuintile.jpg',
       dpi=300, width = 8, height=4)
p2

p2 = ggplot(hipp_avg %>% filter(hipp_quintile == 5), 
            aes(x=factor(time), y=mean, group=group, color=group)) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=mean-se, 
                               ymax=mean+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('% signal change') +
  xlab('Time post-stimulus onset (s)') +
  guides(color=FALSE) +
  scale_color_manual(values=palette)
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/hipp_bytimeX5thquintile.jpg',
       dpi=300, width = 5, height=4)
p2

2b) Signal variation for HC associative hits

# standardize continuous vars
dCleanStandardized_HC = dm %>% filter(pcorr == 1)
dCleanStandardized_HC = dCleanStandardized_HC %>% 
  group_by(subid) %>%
   mutate(ang_logit_z = zscore(ang_logit),
         vtc_logit_z = zscore(vtc_logit),
         hipp_logit_z = zscore(hipp_logit),
         CCN_sig_z = zscore(CCN_sig),
         DAN_sig_z = zscore(DAN_sig),
         CCN_lh_sig_z = zscore(CCN_lh_sig),
         DAN_lh_sig_z = zscore(DAN_lh_sig),
         hipp_sig_z = zscore(hipp_sig),
         hipp_tail_sig_z = zscore(hipp_tail_sig),
         reps = factor(reps),
         hipp_quintile = ntile(hipp_sig, 5),
         CCN_quintile = ntile(CCN_sig, 5),
         DAN_quintile = ntile(DAN_sig, 5),
         CCN_lh_quintile = ntile(CCN_lh_sig, 5),
         DAN_lh_quintile = ntile(DAN_lh_sig, 5),
         hipp_tail_quintile = ntile(hipp_tail_sig, 5),
         vtc_quintile = ntile(vtc_logit, 5),
         hipp_logit_quintile = ntile(hipp_logit, 5),
         ang_quintile = ntile(ang_logit, 5),
         rt_z = zscore(respRT))

dCleanStandardized_HC$rGenHipp<-scale(dCleanStandardized_HC$hipp_sig_z)
dCleanStandardized_HC$ERActUnsigned<-scale(dCleanStandardized_HC$vtc_logit_z)
dCleanStandardized_HC$ERActUnsigned_infpar<-scale(dCleanStandardized_HC$ang_logit_z)
dCleanStandardized_HC$RT_z<-scale(dCleanStandardized_HC$rt_z)

contrasts(dCleanStandardized_HC$group) 
##         [,1]
## control    1
## stress    -1
contrasts(dCleanStandardized_HC$reps)  = c(-1,1); contrasts(dCleanStandardized_HC$reps)
##   [,1]
## 2   -1
## 4    1
contrasts(dCleanStandardized_HC$shockCond) 
##        [,1]
## safe      1
## threat   -1
# look at trial counts/subj
trial_counts = data.frame(with(dCleanStandardized_HC, table(subid)))
trial_counts %>% summarise(min(Freq), max(Freq), mean(Freq), sd(Freq))
##   min(Freq) max(Freq) mean(Freq) sd(Freq)
## 1         8       146   66.59524 34.91387

Subj level effects

datalist = list()
i = 1
for (subject in unique(dCleanStandardized_HC$subid)){
  print(subject)
  fit = lm(vtc_logit_z ~ hipp_sig_z + reps + shockCond + pcorr,
            data=dCleanStandardized %>% filter(subid == subject))
  print(fit$coefficients['hipp_sig_z'])
  dat = data.frame(subid=subject,
                   coef = fit$coefficients['hipp_sig_z'])
  datalist[[i]] <- dat 
  i = 1+i
}
## [1] "ap100"
## hipp_sig_z 
##  0.2213994 
## [1] "ap101"
## hipp_sig_z 
##  0.3373103 
## [1] "ap102"
## hipp_sig_z 
##  0.5305914 
## [1] "ap103"
## hipp_sig_z 
## 0.01740553 
## [1] "ap104"
## hipp_sig_z 
##  0.2433198 
## [1] "ap105"
## hipp_sig_z 
##  0.3827204 
## [1] "ap107"
## hipp_sig_z 
##  0.2027479 
## [1] "ap108"
## hipp_sig_z 
##  0.5068813 
## [1] "ap109"
## hipp_sig_z 
## 0.03096766 
## [1] "ap110"
## hipp_sig_z 
##  -0.095993 
## [1] "ap111"
## hipp_sig_z 
##  0.4177546 
## [1] "ap113"
## hipp_sig_z 
## 0.03273074 
## [1] "ap114"
##   hipp_sig_z 
## -0.007480017 
## [1] "ap115"
## hipp_sig_z 
##  0.4292727 
## [1] "ap116"
## hipp_sig_z 
##  0.0864731 
## [1] "ap117"
## hipp_sig_z 
##  0.1292738 
## [1] "ap118"
## hipp_sig_z 
##   0.363019 
## [1] "ap119"
## hipp_sig_z 
##  0.1547364 
## [1] "ap120"
## hipp_sig_z 
##  0.1606293 
## [1] "ap121"
##  hipp_sig_z 
## -0.06804304 
## [1] "ap122"
## hipp_sig_z 
##  0.3733573 
## [1] "ap158"
## hipp_sig_z 
##  0.1679932 
## [1] "ap150"
## hipp_sig_z 
## 0.07004682 
## [1] "ap152"
## hipp_sig_z 
##  0.2506595 
## [1] "ap153"
## hipp_sig_z 
## -0.1482166 
## [1] "ap154"
## hipp_sig_z 
##  0.5447693 
## [1] "ap155"
## hipp_sig_z 
##  0.3138483 
## [1] "ap157"
## hipp_sig_z 
##  0.2869844 
## [1] "ap159"
## hipp_sig_z 
##  0.1926664 
## [1] "ap160"
## hipp_sig_z 
##  0.7377234 
## [1] "ap161"
## hipp_sig_z 
##   0.307614 
## [1] "ap162"
## hipp_sig_z 
##  0.3733739 
## [1] "ap163"
## hipp_sig_z 
##  0.3261346 
## [1] "ap164"
## hipp_sig_z 
##  0.3638596 
## [1] "ap165"
## hipp_sig_z 
##  0.4880732 
## [1] "ap166"
## hipp_sig_z 
##  0.1295266 
## [1] "ap167"
## hipp_sig_z 
##  0.2138185 
## [1] "ap169"
## hipp_sig_z 
##  0.3528862 
## [1] "ap170"
## hipp_sig_z 
##  0.5648815 
## [1] "ap171"
## hipp_sig_z 
##  0.4931997 
## [1] "ap172"
## hipp_sig_z 
##  0.2994002 
## [1] "ap173"
## hipp_sig_z 
##  0.3095836
slopes_vtcXhipp <- dplyr::bind_rows(datalist) %>% 
  left_join(dCleanStandardized %>% 
                                group_by(subid, group) %>% 
                                summarise(n()))
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
## Joining, by = "subid"
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector
with(slopes_vtcXhipp , boxplot(coef ~ group))

bartlett.test(coef ~ group, data=slopes_vtcXhipp)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  coef by group
## Bartlett's K-squared = 0.019339, df = 1, p-value = 0.8894
t.test(coef ~ group, data=slopes_vtcXhipp, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  coef by group
## t = -1.947, df = 40, p-value = 0.05858
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.231672992  0.004323095
## sample estimates:
## mean in group control  mean in group stress 
##             0.2098667             0.3235417
ggplot(slopes_vtcXhipp, aes(x=group, y=coef)) + 
  geom_boxplot(outlier.alpha = 0)+
  geom_point(position = position_jitter(width=.1)) +
  xlab('') + ylab('Slope (vtc ~ hipp)')

# ## now dont control for pcorr
# datalist = list()
# i = 1
# for (subject in unique(dCleanStandardized_HC$subid)){
#   print(subject)
#   fit = lm(vtc_logit_z ~ hipp_sig_z + reps + shockCond ,
#             data=dCleanStandardized %>% filter(subid == subject))
#   print(fit$coefficients['hipp_sig_z'])
#   dat = data.frame(subid=subject,
#                    coef = fit$coefficients['hipp_sig_z'])
#   datalist[[i]] <- dat 
#   i = 1+i
# }
# 
# slopes_vtcXhipp <- dplyr::bind_rows(datalist) %>% 
#   left_join(dCleanStandardized %>% 
#                                 group_by(subid, group) %>% 
#                                 summarise(n()))
# with(slopes_vtcXhipp , boxplot(coef ~ group))
# bartlett.test(coef ~ group, data=slopes_vtcXhipp)
# t.test(coef ~ group, data=slopes_vtcXhipp, var.equal=TRUE)
with(slopes_vtcXhipp %>% left_join(assoc_d %>% 
                                group_by(subid, group) %>% 
                                summarise(assoc_d = mean(assoc_d))),
     summary(lm(coef ~ assoc_d)))
## Joining, by = c("subid", "group")
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector
## 
## Call:
## lm(formula = coef ~ assoc_d)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.42954 -0.12529  0.01418  0.12295  0.45775 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.29564    0.05885   5.024  1.1e-05 ***
## assoc_d     -0.02706    0.04312  -0.628    0.534    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1968 on 40 degrees of freedom
## Multiple R-squared:  0.009753,   Adjusted R-squared:  -0.015 
## F-statistic: 0.394 on 1 and 40 DF,  p-value: 0.5338
summary(lmer(CCN_lh_sig ~ group + (1|subid), 
             data=dCleanStandardized_HC %>% filter(CCN_lh_quintile == 1)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: CCN_lh_sig ~ group + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(CCN_lh_quintile == 1)
## 
## REML criterion at convergence: -90.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -5.1887 -0.3880  0.2501  0.6162  1.9068 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.01756  0.1325  
##  Residual             0.04328  0.2080  
## Number of obs: 580, groups:  subid, 42
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept) -0.29182    0.02279 37.28000 -12.805 3.11e-15 ***
## group1      -0.01607    0.02279 37.28000  -0.705    0.485    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.085
summary(lmer(CCN_lh_sig ~ group + (1|subid), 
             data=dCleanStandardized_HC %>% filter(CCN_lh_quintile == 2)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: CCN_lh_sig ~ group + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(CCN_lh_quintile == 2)
## 
## REML criterion at convergence: -1549.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.86384 -0.72655  0.05504  0.74151  2.75467 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.006636 0.08146 
##  Residual             0.002757 0.05251 
## Number of obs: 557, groups:  subid, 42
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)
## (Intercept) -0.001804   0.012872 37.030000  -0.140    0.889
## group1      -0.012634   0.012872 37.030000  -0.982    0.333
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.055
summary(lmer(CCN_lh_sig ~ group + (1|subid), 
             data=dCleanStandardized_HC %>% filter(CCN_lh_quintile == 3)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: CCN_lh_sig ~ group + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(CCN_lh_quintile == 3)
## 
## REML criterion at convergence: -1662.5
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.87226 -0.63268 -0.01221  0.70378  2.70905 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.006989 0.08360 
##  Residual             0.002240 0.04732 
## Number of obs: 559, groups:  subid, 42
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  0.14534    0.01317 36.66000  11.039 3.27e-13 ***
## group1      -0.01491    0.01317 36.66000  -1.133    0.265    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.056
summary(lmer(CCN_lh_sig ~ group + (1|subid), 
             data=dCleanStandardized_HC %>% filter(CCN_lh_quintile == 4)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: CCN_lh_sig ~ group + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(CCN_lh_quintile == 4)
## 
## REML criterion at convergence: -1455.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6040 -0.7250 -0.0121  0.7102  3.7097 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.009020 0.09497 
##  Residual             0.003237 0.05689 
## Number of obs: 557, groups:  subid, 42
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  0.29631    0.01496 38.95000  19.803   <2e-16 ***
## group1      -0.01863    0.01496 38.95000  -1.245    0.221    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.054
summary(lmer(CCN_lh_sig ~ group + (1|subid), 
             data=dCleanStandardized_HC %>% filter(CCN_lh_quintile == 5)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: CCN_lh_sig ~ group + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(CCN_lh_quintile == 5)
## 
## REML criterion at convergence: -397.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.8063 -0.6751 -0.2447  0.5304  4.4087 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.01721  0.1312  
##  Residual             0.02333  0.1527  
## Number of obs: 544, groups:  subid, 42
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  0.55661    0.02178 40.08000  25.558   <2e-16 ***
## group1      -0.04077    0.02178 40.08000  -1.872   0.0685 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##        (Intr)
## group1 -0.076

2b (i): Does hipp still track VTC for HC recollection?

deq.2b<-lmer(ERActUnsigned ~ group*(rGenHipp) + reps + shockCond +
              (-1 + rGenHipp|subid)+
              (1|subid), 
            data=dCleanStandardized_HC)
# uncorrelate random slopes and intercepts
summary(deq.2b)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (rGenHipp) + reps + shockCond + (-1 +  
##     rGenHipp | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7772.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.6305 -0.6618 -0.0434  0.6514  3.6190 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    rGenHipp    0.02952  0.1718  
##  subid.1  (Intercept) 0.00000  0.0000  
##  Residual             0.91814  0.9582  
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)     -3.323e-03  1.925e-02  2.749e+03  -0.173   0.8630    
## group1           4.574e-04  1.890e-02  2.748e+03   0.024   0.9807    
## rGenHipp         2.417e-01  3.358e-02  3.460e+01   7.197 2.27e-08 ***
## reps1            1.610e-02  1.858e-02  2.776e+03   0.867   0.3863    
## shockCond1       5.567e-03  1.821e-02  2.772e+03   0.306   0.7598    
## group1:rGenHipp -6.581e-02  3.359e-02  3.460e+01  -1.959   0.0582 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1
## group1      -0.283                            
## rGenHipp     0.002  0.000                     
## reps1       -0.189  0.020 -0.009              
## shockCond1  -0.025  0.020  0.003 -0.012       
## grp1:rGnHpp  0.003  0.000 -0.126 -0.016 -0.005
# look at raw reinstatement by median split of hipp (un-zscored)
dat = dCleanStandardized_HC %>%
  filter(pcorr == 1) %>%
  group_by(subid, group) %>%
  mutate(hipp_med = ntile(hipp_sig, 2)) %>%
  ungroup()

summary(lmer(vtc_logit ~ group + reps + shockCond + 
              (1|subid), 
            data=dat %>% filter(hipp_med == 1)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ group + reps + shockCond + (1 | subid)
##    Data: dat %>% filter(hipp_med == 1)
## 
## REML criterion at convergence: 6831.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.0915 -0.6310 -0.0181  0.5844  4.3446 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.3039   0.5513  
##  Residual             7.2466   2.6919  
## Number of obs: 1409, groups:  subid, 42
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)  
## (Intercept) 2.999e-01  1.177e-01 3.650e+01   2.548   0.0152 *
## group1      2.895e-01  1.167e-01 3.560e+01   2.481   0.0180 *
## reps1       9.286e-02  7.359e-02 1.393e+03   1.262   0.2072  
## shockCond1  2.028e-02  7.203e-02 1.382e+03   0.282   0.7783  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) group1 reps1 
## group1     -0.149              
## reps1      -0.132  0.031       
## shockCond1 -0.013  0.005  0.026
summary(lmer(vtc_logit ~ group + reps + shockCond + 
              (1|subid), 
            data=dat %>% filter(hipp_med == 2)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ group + reps + shockCond + (1 | subid)
##    Data: dat %>% filter(hipp_med == 2)
## 
## REML criterion at convergence: 6725.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.6091 -0.6466 -0.0393  0.6514  3.2923 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.6986   0.8358  
##  Residual             7.1132   2.6670  
## Number of obs: 1388, groups:  subid, 42
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)    1.38884    0.15403   39.20000   9.016 4.18e-11 ***
## group1        -0.09567    0.15322   38.40000  -0.624    0.536    
## reps1          0.04690    0.07404 1362.40000   0.633    0.527    
## shockCond1    -0.01133    0.07235 1358.50000  -0.157    0.876    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) group1 reps1 
## group1     -0.105              
## reps1      -0.103 -0.011       
## shockCond1 -0.017  0.025 -0.055
# what about rep effect?
summary(lmer(ERActUnsigned ~ group*(rGenHipp) + reps + shockCond + 
              (-1 + rGenHipp|subid)+
              (-1 + reps|subid)+
              (1|subid), 
            data=dCleanStandardized_HC))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (rGenHipp) + reps + shockCond + (-1 +  
##     rGenHipp | subid) + (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7771.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.6301 -0.6560 -0.0425  0.6480  3.5980 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    rGenHipp    0.029372 0.17138       
##  subid.1  reps2       0.003849 0.06204       
##           reps4       0.001812 0.04257  -1.00
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.915546 0.95684       
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)     -4.555e-03  1.934e-02  1.169e+03  -0.236   0.8138    
## group1           1.283e-03  1.890e-02  2.748e+03   0.068   0.9459    
## rGenHipp         2.418e-01  3.353e-02  3.460e+01   7.211  2.2e-08 ***
## reps1            1.857e-02  2.064e-02  4.150e+01   0.900   0.3735    
## shockCond1       5.727e-03  1.819e-02  2.766e+03   0.315   0.7530    
## group1:rGenHipp -6.578e-02  3.353e-02  3.460e+01  -1.962   0.0579 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1
## group1      -0.281                            
## rGenHipp     0.001  0.000                     
## reps1       -0.212  0.018 -0.007              
## shockCond1  -0.025  0.021  0.003 -0.010       
## grp1:rGnHpp  0.003 -0.001 -0.126 -0.014 -0.005

Hippocampal activity does scale with VTC reinstatement strength across HC recollection; there’s no effect of encoding strength on VTC reinstatement strength when controlling for hippocampal activity. There’s a marginal group interaction, similar to that seen across all old items.

Plot

## collapse across rep
dm_avg = dm %>% filter(pcorr == 1) %>%
  group_by(subid) %>%
  mutate(hipp_quintile = ntile(hipp_sig, 5)) %>%
  group_by(subid, group, hipp_quintile, reps) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n()) %>%
  group_by(subid, group, hipp_quintile) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n()) 

dfwc = summarySEwithin(dm_avg, measurevar="vtc_logit", withinvars=c("hipp_quintile"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: hipp_quintile
dfwc
##      group hipp_quintile  N  vtc_logit vtc_logit_norm        sd        se
## 1  control             1 22  0.2010613     0.07894803 1.2933174 0.2757362
## 2  control             2 22  0.8395520     0.71743873 1.0876357 0.2318847
## 3  control             3 22  1.0152743     0.89316103 0.7749401 0.1652178
## 4  control             4 22  1.1257937     1.00368039 0.7405889 0.1578941
## 5  control             5 22  1.6325535     1.51044014 1.0452088 0.2228393
## 6   stress             1 20 -0.3198339    -0.18550922 1.0998454 0.2459329
## 7   stress             2 20  0.1193252     0.25364982 0.7727711 0.1727969
## 8   stress             3 20  0.8028162     0.93714080 1.1203010 0.2505069
## 9   stress             4 20  1.0758159     1.21014052 0.9566780 0.2139197
## 10  stress             5 20  1.8539218     1.98824641 1.4295128 0.3196488
##           ci
## 1  0.5734248
## 2  0.4822307
## 3  0.3435892
## 4  0.3283587
## 5  0.4634196
## 6  0.5147435
## 7  0.3616680
## 8  0.5243170
## 9  0.4477391
## 10 0.6690326
p2 = ggplot(dfwc, aes(x=hipp_quintile, y=vtc_logit, group=group, color=group)) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=vtc_logit-se, 
                               ymax=vtc_logit+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('Reinstatement strength\n(logits)')+
  xlab('Hippocampal activity (quintiles)')+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p2

ggsave(p2, 
       filename ='~/Experiments/AP/figs/logitXhipp_quintile_HCrecollection_wholehipp.jpg', 
       dpi=150, width = 6, height=4)
p2

2b (ii): Is frontoparietal activity modulated by RT/difficulty of HC decisions?

Predict that more uncertain HC recollection decisions should scale with RT + frontoparietal bold (particularly in LH). We’ll test lh first, then look to see if holds in bilateral network.

Since encoding strength tracks RT for HC decisions (faster RTs for stronger encoding items), these might require less FP activity to recall.

Would hipp be the reverse? Greater activity for more vivid/confident/faster memories? Or, would hipp be greater for slower HC recollection of associate, where potentially have retrieved more things/activated more neurons in hipp before settling on correct response?

Include all subjects included in fMRI analyses:

d = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_place_byreps_avg_46810_filtartloc_scalewithinrun.csv')

# filter d to just good subjs, and only OLD items
d = d %>%
  filter(cond %in% c('sourcemiss_hi', 'sourcehit', 'M', 'itemhit_lo')) %>%
  mutate(pcorr = factor(ifelse(cond == "sourcehit", 1, 0)),
         vtc_logit = avg_logit)

dt %>% filter(shock_and_post == 2) # one subj w/consecutive shocks - trial needs to be removed (though mem_condition == 'nuisance')
##      X run trial    onset duration shockCond shockTrial target associate
## 1 6677   5    13 141.3117  11.5306    threat          1   WHIP     ocean
##      resp acc accSpec respRT subid       group remove anxious happy safe
## 1 outdoor   H   HO_Hi 0.1927 ap160 stress-fmri     NA       4     3    6
##   stressed life_stress sleep cond_orig    cond reps shock_and_post conf
## 1        5           3   4.5      TO_4 outdoor    4              2   Hi
##   onset_adj mem_conditions obj_conditions onset_code      rt_z
## 1  129.3117       nuisance       nuisance   nuisance -3.136573
##   mem_conditions_byrep onset_code_byrep
## 1           nuisance-4       nuisance-4
# Merge w/other behavioral info
d = dt %>%
  mutate(onset=onset_adj, img_type=cond) %>% 
  dplyr::select(-group, -reps, -cond) %>%
  right_join(d, by=c('subid', 'run', 'onset')) %>%
  mutate(subid = factor(subid), imgType = factor(img_type))
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
dim(d)
## [1] 6942   50
d = d %>% filter(shock_and_post == 0)
dim(d)
## [1] 6941   50
# Read in hipp BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-hippocampus.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-hippocampus.csv')
# dim(roi_lh); dim(roi_rh)

# Take timepoints of interest for old trials, and collapse across hemispheres
roi_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(hipp_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# Read in hipp tail BOLD
roi_tail_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-hippocampus-tail.csv')
roi_tail_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-hippocampus-tail.csv')

# Take timepoints of interest for old trials, and collapse across hemispheres
roi_tail_f = bind_rows("lh" = roi_tail_lh, "rh" = roi_tail_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(hipp_tail_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# Read in angular BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-DefaultA_IPL.csv')
angular_lh_f = roi_lh %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, run, onset) %>%
  summarise(angular_lh_sig = mean_(mean_activity)) %>% ungroup()

# Read in RSP BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-DefaultC_Rsp.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-DefaultC_Rsp.csv')

# Take timepoints of interest for old trials, and collapse across hemispheres
rsp_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(rsp_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# Read in CCN BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-frontoparietal.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-frontoparietal.csv')
# dim(roi_lh); dim(roi_rh)

# Take timepoints of interest for old trials, and collapse across hemispheres
CCN_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(CCN_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# also, just for LH
CCN_lh_f = roi_lh %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, run, onset) %>%
  summarise(CCN_lh_sig = mean_(mean_activity)) %>% ungroup()

# Read in DAN BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-dorsalattn.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-dorsalattn.csv')
# dim(roi_lh); dim(roi_rh)

# Take timepoints of interest for old trials, and collapse across hemispheres
DAN_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(DAN_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# also, just for LH
DAN_lh_f = roi_lh %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, run, onset) %>%
  summarise(DAN_lh_sig = mean_(mean_activity)) %>% ungroup()

# Other reinstatement
d_infpar = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_inferiorparietal_place_byreps_avg_46810_filtartloc_scalewithinrun.csv') %>%
  filter(cond %in% c('sourcemiss_hi', 'sourcehit', 'M', 'itemhit_lo')) %>%
  mutate(ang_logit = avg_logit) %>%
  dplyr::select(subid, run, onset, ang_logit)

d_hipp = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_bilat-hippocampus_place_byreps_avg_46810_filtartloc_scalewithinrun.csv') %>%
  filter(cond %in% c('sourcemiss_hi', 'sourcehit', 'M', 'itemhit_lo')) %>%
  mutate(pcorr = factor(ifelse(cond == "sourcehit", 1, 0)),
         hipp_logit = avg_logit) %>%
  dplyr::select(subid, run, onset, hipp_logit)

# Merge w/VTC classifier evidence
dm_allfmri = d %>%
  left_join(roi_f, by=c('subid', 'run', 'onset')) %>%
  left_join(roi_tail_f, by=c('subid', 'run', 'onset')) %>%
  left_join(DAN_f, by=c('subid', 'run', 'onset')) %>%
  left_join(CCN_f, by=c('subid', 'run', 'onset')) %>%
  left_join(rsp_f, by=c('subid', 'run', 'onset')) %>%
  left_join(angular_lh_f, by=c('subid', 'run', 'onset')) %>%
  left_join(DAN_lh_f, by=c('subid', 'run', 'onset')) %>%
  left_join(CCN_lh_f, by=c('subid', 'run', 'onset')) %>%
  left_join(d_infpar, by=c('subid', 'run', 'onset')) %>%
  left_join(d_hipp, by=c('subid', 'run', 'onset')) %>%
  group_by(subid) %>%
  mutate(ang_logit_z = zscore(ang_logit),
         vtc_logit_z = zscore(vtc_logit),
         hipp_logit_z = zscore(hipp_logit),
         CCN_sig_z = zscore(CCN_sig),
         rsp_sig_z = zscore(rsp_sig),
         DAN_sig_z = zscore(DAN_sig),
         angular_lh_sig_z = zscore(angular_lh_sig),
         CCN_lh_sig_z = zscore(CCN_lh_sig),
         DAN_lh_sig_z = zscore(DAN_lh_sig),
         hipp_sig_z = zscore(hipp_sig),
         hipp_tail_sig_z = zscore(hipp_tail_sig),
         reps = factor(reps),
         hipp_quintile = ntile(hipp_sig, 5),
         rsp_quintile = ntile(rsp_sig, 5),
         CCN_quintile = ntile(CCN_sig, 5),
         DAN_quintile = ntile(DAN_sig, 5),
         angular_lh_sig_quintile = ntile(angular_lh_sig, 5),
         CCN_lh_quintile = ntile(CCN_lh_sig, 5),
         DAN_lh_quintile = ntile(DAN_lh_sig, 5),
         hipp_tail_quintile = ntile(hipp_tail_sig, 5),
         vtc_quintile = ntile(vtc_logit, 5),
         hipp_logit_quintile = ntile(hipp_logit, 5),
         ang_quintile = ntile(ang_logit, 5)) %>%
  ungroup() %>%
  mutate(subid = factor(subid),
         cond = factor(cond),
         condition = factor(condition))
dim(dm_allfmri)
## [1] 6941   82
with(dm_allfmri, table(subid, reps))
##        reps
## subid    2  4
##   ap100 76 78
##   ap101 83 82
##   ap102 80 79
##   ap103 83 79
##   ap104 82 83
##   ap105 81 81
##   ap107 79 82
##   ap108 72 74
##   ap109 81 77
##   ap110 82 81
##   ap111 82 84
##   ap113 83 83
##   ap114 81 81
##   ap115 78 82
##   ap116 80 82
##   ap117 84 80
##   ap118 83 81
##   ap119 80 81
##   ap120 79 76
##   ap121 84 81
##   ap122 84 82
##   ap150 77 78
##   ap152 73 78
##   ap153 77 75
##   ap154 67 78
##   ap155 69 66
##   ap157 77 79
##   ap158 84 83
##   ap159 81 81
##   ap160 66 64
##   ap161 81 79
##   ap162 75 80
##   ap163 83 78
##   ap164 79 79
##   ap165 75 81
##   ap166 79 79
##   ap167 76 77
##   ap168 79 82
##   ap169 77 79
##   ap170 81 81
##   ap171 81 81
##   ap172 80 76
##   ap173 73 74
##   ap174 77 80
str(dm_allfmri)
## Classes 'tbl_df', 'tbl' and 'data.frame':    6941 obs. of  82 variables:
##  $ X.x                    : int  0 2 3 4 5 7 8 11 14 15 ...
##  $ run                    : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ trial                  : int  1 3 4 5 6 8 9 12 15 16 ...
##  $ onset                  : num  0.0191 19.8642 29.3132 40.6786 50.4701 ...
##  $ duration               : num  10.67 9.42 11.34 9.76 9.12 ...
##  $ shockCond              : Factor w/ 2 levels "safe","threat": 1 1 1 1 1 1 1 1 1 1 ...
##  $ shockTrial             : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ target                 : Factor w/ 252 levels "ACCORDIAN","ACROBAT",..: 15 238 116 114 183 224 87 102 192 191 ...
##  $ associate              : Factor w/ 241 levels "\002\002","\002",..: 68 237 126 61 175 233 53 118 173 84 ...
##  $ resp                   : Factor w/ 4 levels "foil","indoor",..: 2 2 4 4 4 1 1 1 4 2 ...
##  $ acc                    : Factor w/ 6 levels "CR","FA","H",..: 6 3 3 3 3 4 4 4 3 3 ...
##  $ accSpec                : Factor w/ 15 levels "CR","FAI_Hi",..: 14 6 8 8 8 10 10 10 8 6 ...
##  $ respRT                 : num  2.11 1.68 1.73 1.37 2.15 ...
##  $ subid                  : Factor w/ 44 levels "ap100","ap101",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ remove                 : logi  NA NA NA NA NA NA ...
##  $ anxious                : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ happy                  : int  2 2 2 2 2 2 2 2 2 2 ...
##  $ safe                   : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ stressed               : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ life_stress            : int  4 4 4 4 4 4 4 4 4 4 ...
##  $ sleep                  : num  4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 ...
##  $ cond_orig              : Factor w/ 5 levels "F_0","TI_2","TI_4",..: 5 2 4 4 5 3 2 4 5 2 ...
##  $ shock_and_post         : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ conf                   : Factor w/ 3 levels "Hi","Lo","N": 1 1 1 1 1 3 3 3 1 1 ...
##  $ onset_adj              : num  0.0191 19.8642 29.3132 40.6786 50.4701 ...
##  $ mem_conditions         : Factor w/ 7 levels "CR","FA","itemhit_lo",..: 7 6 6 6 6 4 4 4 6 6 ...
##  $ obj_conditions         : Factor w/ 3 levels "new","nuisance",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ onset_code             : Factor w/ 6 levels "CR","FA","itemhit",..: 3 6 6 6 6 4 4 4 6 6 ...
##  $ rt_z                   : num  -1.2039 -0.746 -0.6739 -1.2235 -0.0194 ...
##  $ mem_conditions_byrep   : Factor w/ 13 levels "CR-0","FA-0",..: 13 10 10 10 11 6 5 5 11 10 ...
##  $ onset_code_byrep       : Factor w/ 11 levels "CR-0","FA-0",..: 4 10 10 10 11 6 5 5 11 10 ...
##  $ img_type               : Factor w/ 3 levels "foil","indoor",..: 3 2 3 3 3 2 2 3 3 2 ...
##  $ X.y                    : int  2 8 11 14 17 23 26 35 44 47 ...
##  $ index                  : int  2 8 11 14 17 23 26 35 44 47 ...
##  $ group                  : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ condition              : Factor w/ 8 levels "itemhit_lo-2",..: 8 5 5 5 6 4 3 3 6 5 ...
##  $ category               : Factor w/ 1 level "place": 1 1 1 1 1 1 1 1 1 1 ...
##  $ X0                     : num  -6.635 -9.265 6.804 8.431 0.203 ...
##  $ X2                     : num  -6.32 -4.39 7.22 3.92 -3.54 ...
##  $ X4                     : num  -1.49 5.79 4.22 1.8 -2.75 ...
##  $ X6                     : num  2.59 5.69 -3.03 3.7 3.74 ...
##  $ X8                     : num  -1.03 8.65 -1.68 -1.28 -2.28 ...
##  $ X10                    : num  -0.642 6.486 8.468 -0.23 -9.405 ...
##  $ X12                    : num  -1.1 6.64 11.49 -3.55 -5.64 ...
##  $ avg_logit              : num  -0.145 6.655 1.996 0.998 -2.673 ...
##  $ cond                   : Factor w/ 4 levels "itemhit_lo","M",..: 4 3 3 3 3 2 2 2 3 3 ...
##  $ reps                   : Factor w/ 2 levels "2","4": 2 1 1 1 2 2 1 1 2 1 ...
##  $ pcorr                  : Factor w/ 2 levels "0","1": 1 2 2 2 2 1 1 1 2 2 ...
##  $ vtc_logit              : num  -0.145 6.655 1.996 0.998 -2.673 ...
##  $ imgType                : Factor w/ 2 levels "indoor","outdoor": 2 1 2 2 2 1 1 2 2 1 ...
##  $ hipp_sig               : num  0.2754 0.4613 -0.1955 -0.0154 -0.14 ...
##  $ hipp_tail_sig          : num  0.11449 0.49252 -0.00556 -0.06895 -0.13196 ...
##  $ DAN_sig                : num  0.175 0.658 0.225 -0.262 -0.395 ...
##  $ CCN_sig                : num  0.367 0.4107 0.0192 -0.1273 -0.2068 ...
##  $ rsp_sig                : num  0.3053 1.5956 -0.0991 -0.19 -0.5123 ...
##  $ angular_lh_sig         : num  0.20058 0.85916 -0.09532 0.00574 -0.04293 ...
##  $ DAN_lh_sig             : num  0.212 0.585 0.183 -0.233 -0.383 ...
##  $ CCN_lh_sig             : num  0.3687 0.2566 0.1633 -0.1271 -0.0121 ...
##  $ ang_logit              : num  -2.066 5.935 0.249 -3.792 -6.49 ...
##  $ hipp_logit             : num  -2.553 1.418 -1.783 -2.571 -0.555 ...
##  $ ang_logit_z            : num  -0.474 1.931 0.222 -0.993 -1.804 ...
##  $ vtc_logit_z            : num  -0.148 1.895 0.495 0.195 -0.907 ...
##  $ hipp_logit_z           : num  -0.491 1.406 -0.123 -0.499 0.464 ...
##  $ CCN_sig_z              : num  0.6436 0.7336 -0.0722 -0.3738 -0.5374 ...
##  $ rsp_sig_z              : num  0.209 2.071 -0.375 -0.506 -0.971 ...
##  $ DAN_sig_z              : num  0.391 1.606 0.516 -0.711 -1.046 ...
##  $ angular_lh_sig_z       : num  0.177 1.513 -0.423 -0.218 -0.317 ...
##  $ CCN_lh_sig_z           : num  0.537 0.31 0.121 -0.468 -0.235 ...
##  $ DAN_lh_sig_z           : num  0.437 1.389 0.363 -0.7 -1.082 ...
##  $ hipp_sig_z             : num  0.537 0.967 -0.552 -0.135 -0.424 ...
##  $ hipp_tail_sig_z        : num  0.167 1.146 -0.143 -0.307 -0.47 ...
##  $ hipp_quintile          : int  4 5 2 3 2 1 4 1 3 4 ...
##  $ rsp_quintile           : int  3 5 2 2 1 1 4 1 3 3 ...
##  $ CCN_quintile           : int  4 4 3 2 2 1 5 1 3 3 ...
##  $ DAN_quintile           : int  4 5 4 2 1 1 4 1 2 4 ...
##  $ angular_lh_sig_quintile: int  3 5 2 3 2 1 2 1 4 4 ...
##  $ CCN_lh_quintile        : int  4 3 3 2 3 1 5 1 4 3 ...
##  $ DAN_lh_quintile        : int  4 5 4 2 1 1 4 1 3 4 ...
##  $ hipp_tail_quintile     : int  3 5 3 2 2 1 4 1 3 5 ...
##  $ vtc_quintile           : int  3 5 4 3 1 2 2 1 5 4 ...
##  $ hipp_logit_quintile    : int  2 5 3 2 4 2 5 3 1 3 ...
##  $ ang_quintile           : int  2 5 4 1 1 1 4 2 4 5 ...
# set up contrasts
contrasts(dm_allfmri$pcorr) = c(-1,1); contrasts(dm_allfmri$pcorr)
##   [,1]
## 0   -1
## 1    1
contrasts(dm_allfmri$reps) = c(-1,1); contrasts(dm_allfmri$reps)
##   [,1]
## 2   -1
## 4    1
contrasts(dm_allfmri$group) = c(1,-1); contrasts(dm_allfmri$group)
##         [,1]
## control    1
## stress    -1
contrasts(dm_allfmri$shockCond) = c(1,-1); contrasts(dm_allfmri$shockCond)
##        [,1]
## safe      1
## threat   -1
# standardize continuous vars
dCleanStandardized_HC_allfmri = dm_allfmri %>% filter(pcorr == 1)
with(dCleanStandardized_HC_allfmri, table(subid, reps))
##        reps
## subid    2  4
##   ap100 38 49
##   ap101 37 65
##   ap102 23 43
##   ap103 48 63
##   ap104 67 79
##   ap105 49 68
##   ap107 60 62
##   ap108 12 16
##   ap109 20 38
##   ap110  3 17
##   ap111 23 50
##   ap113 28 47
##   ap114 43 58
##   ap115 32 45
##   ap116 69 75
##   ap117 36 48
##   ap118 21 41
##   ap119 44 68
##   ap120 29 42
##   ap121 16 17
##   ap122 40 55
##   ap150 28 38
##   ap152 15 25
##   ap153  7 24
##   ap154 14 28
##   ap155 18 20
##   ap157 13 38
##   ap158  2  9
##   ap159 21 29
##   ap160 23 28
##   ap161  9 18
##   ap162 19 22
##   ap163 48 59
##   ap164 28 53
##   ap165 28 36
##   ap166 27 44
##   ap167 14 24
##   ap168 18 28
##   ap169 33 36
##   ap170 27 47
##   ap171  9 24
##   ap172  9 11
##   ap173  2  6
##   ap174 35 49
dCleanStandardized_HC_allfmri = dCleanStandardized_HC_allfmri %>% 
  group_by(subid) %>%
   mutate(ang_logit_z = zscore(ang_logit),
         vtc_logit_z = zscore(vtc_logit),
         hipp_logit_z = zscore(hipp_logit),
         CCN_sig_z = zscore(CCN_sig),
         DAN_sig_z = zscore(DAN_sig),
         CCN_lh_sig_z = zscore(CCN_lh_sig),
         DAN_lh_sig_z = zscore(DAN_lh_sig),
         hipp_sig_z = zscore(hipp_sig),
         hipp_tail_sig_z = zscore(hipp_tail_sig),
         reps = factor(reps),
         hipp_quintile = ntile(hipp_sig, 5),
         CCN_quintile = ntile(CCN_sig, 5),
         DAN_quintile = ntile(DAN_sig, 5),
         CCN_lh_quintile = ntile(CCN_lh_sig, 5),
         DAN_lh_quintile = ntile(DAN_lh_sig, 5),
         hipp_tail_quintile = ntile(hipp_tail_sig, 5),
         vtc_quintile = ntile(vtc_logit, 5),
         hipp_logit_quintile = ntile(hipp_logit, 5),
         ang_quintile = ntile(ang_logit, 5),
         rt_z = zscore(respRT)) %>%
  ungroup()

dCleanStandardized_HC_allfmri$rGenHipp<-scale(dCleanStandardized_HC_allfmri$hipp_sig_z)
dCleanStandardized_HC_allfmri$ERActUnsigned<-scale(dCleanStandardized_HC_allfmri$vtc_logit_z)
dCleanStandardized_HC_allfmri$ERActUnsigned_infpar<-scale(dCleanStandardized_HC_allfmri$ang_logit_z)
dCleanStandardized_HC_allfmri$RT_z<-scale(dCleanStandardized_HC_allfmri$rt_z)

contrasts(dCleanStandardized_HC_allfmri$group) 
##         [,1]
## control    1
## stress    -1
contrasts(dCleanStandardized_HC_allfmri$reps)  = c(-1,1); contrasts(dCleanStandardized_HC_allfmri$reps)
##   [,1]
## 2   -1
## 4    1
contrasts(dCleanStandardized_HC_allfmri$shockCond) 
##        [,1]
## safe      1
## threat   -1

Modulation of HC recollection decisions by RT

LH CCN

mean(dCleanStandardized_HC_allfmri$RT_z)
## [1] -1.242399e-17
sd(dCleanStandardized_HC_allfmri$RT_z)
## [1] 1
mean(dCleanStandardized_HC_allfmri %>% filter(subid =='ap150') %>% pull(RT_z))
## [1] 1.233477e-16
sd(dCleanStandardized_HC_allfmri %>% filter(subid =='ap150') %>% pull(RT_z))
## [1] 1.00743
with(dCleanStandardized_HC_allfmri, table(subid))
## subid
## ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ap110 ap111 ap113 
##    87   102    66   111   146   117   122    28    58    20    73    75 
## ap114 ap115 ap116 ap117 ap118 ap119 ap120 ap121 ap122 ap150 ap152 ap153 
##   101    77   144    84    62   112    71    33    95    66    40    31 
## ap154 ap155 ap157 ap158 ap159 ap160 ap161 ap162 ap163 ap164 ap165 ap166 
##    42    38    51    11    50    51    27    41   107    81    64    71 
## ap167 ap168 ap169 ap170 ap171 ap172 ap173 ap174 
##    38    46    69    74    33    20     8    84
dCleanStandardized_HC_allfmri %>% group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    22
# first lh only
fit  = lmer(scale(CCN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri)
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_lh_sig_z) ~ group * (RT_z + reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri
## 
## REML criterion at convergence: 8277.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8445 -0.6218  0.0195  0.6429  3.7469 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  subid    reps2       9.075e-15 9.526e-08      
##           reps4       7.169e-15 8.467e-08 -1.00
##  subid.1  RT_z        2.979e-03 5.458e-02      
##  subid.2  (Intercept) 0.000e+00 0.000e+00      
##  Residual             9.756e-01 9.877e-01      
## Number of obs: 2927, groups:  subid, 44
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -4.040e-03  1.914e-02  2.884e+03  -0.211   0.8329    
## group1       -7.167e-03  1.914e-02  2.884e+03  -0.374   0.7081    
## RT_z          1.275e-01  2.090e-02  3.610e+01   6.098 5.08e-07 ***
## reps1         2.332e-02  1.931e-02  2.915e+03   1.208   0.2273    
## shockCond1    1.368e-02  1.829e-02  2.919e+03   0.748   0.4546    
## group1:RT_z   5.394e-02  2.090e-02  3.610e+01   2.581   0.0141 *  
## group1:reps1  3.998e-02  1.931e-02  2.915e+03   2.071   0.0385 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 g1:RT_
## group1      -0.234                                   
## RT_z        -0.021  0.004                            
## reps1       -0.200  0.064  0.106                     
## shockCond1  -0.016  0.014 -0.012 -0.015              
## group1:RT_z  0.004 -0.021 -0.185 -0.010  0.011       
## group1:rps1  0.064 -0.201 -0.009 -0.228 -0.014  0.106
#make sure holds when removing rep effect
# summary(lmer(scale(CCN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + RT_z|subid)+
#               (1 |subid),
#             data=dCleanStandardized_HC_allfmri))

# explore interaction of group * rt
summary(lmer(scale(CCN_lh_sig_z) ~ RT_z + reps  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri%>% filter(group == 'control')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_lh_sig_z) ~ RT_z + reps + shockCond + (-1 + reps |  
##     subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(group == "control")
## 
## REML criterion at convergence: 5052.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8479 -0.6044  0.0358  0.6425  3.7712 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       8.220e-15 9.066e-08  NaN
##  subid.1  RT_z        2.648e-03 5.146e-02     
##  subid.2  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.649e-01 9.823e-01     
## Number of obs: 1795, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept) -1.116e-02  2.356e-02  1.772e+03  -0.474  0.63579    
## RT_z         1.813e-01  2.624e-02  1.630e+01   6.909 3.16e-06 ***
## reps1        6.339e-02  2.386e-02  1.782e+03   2.657  0.00795 ** 
## shockCond1   4.924e-03  2.322e-02  1.789e+03   0.212  0.83207    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.022              
## reps1      -0.177  0.123       
## shockCond1 -0.002 -0.001 -0.030
summary(lmer(scale(CCN_lh_sig_z) ~ RT_z + reps + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>% filter(group == 'stress'),
            control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_lh_sig_z) ~ RT_z + reps + shockCond + (-1 + reps |  
##     subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(group == "stress")
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 3223.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7767 -0.6509  0.0018  0.6528  3.1614 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.004215 0.06492       
##           reps4       0.001724 0.04152  -1.00
##  subid.1  RT_z        0.003693 0.06077       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.989763 0.99487       
## Number of obs: 1132, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept)  2.546e-03  3.047e-02  4.557e+02   0.084   0.9334  
## RT_z         7.327e-02  3.300e-02  1.690e+01   2.220   0.0404 *
## reps1       -1.663e-02  3.292e-02  1.610e+01  -0.505   0.6204  
## shockCond1   2.774e-02  2.968e-02  1.127e+03   0.935   0.3501  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.020              
## reps1      -0.235  0.088       
## shockCond1 -0.032 -0.023  0.003
# check to make sure simple effects are same
# contrasts(dCleanStandardized_HC_allfmri$group) = c(0,1)
# summary(lmer(scale(CCN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + reps|subid)+
#               (-1 + RT_z|subid)+
#               (1 |subid),
#             data=dCleanStandardized_HC_allfmri))

# contrasts(dCleanStandardized_HC_allfmri$group) = c(1,0)
# summary(lmer(scale(CCN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + reps|subid)+
#               (-1 + RT_z|subid)+
#               (1 |subid),
#             data=dCleanStandardized_HC_allfmri))
# contrasts(dCleanStandardized_HC_allfmri$group) = c(1,-1)

# interaction between shockcond and RT on CCN? in stress group
# remove subjs w/trial counts/bin < 6
dCleanStandardized_HC_allfmri %>% filter(group == 'stress') %>% 
  group_by(subid, shockCond) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, shockCond, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 1 x 3
##    subid shockCond count
##   <fctr>    <fctr> <dbl>
## 1  ap173    threat     1
summary(lmer(scale(CCN_lh_sig_z) ~ (RT_z + reps) + shockCond +
               shockCond:RT_z +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
               (-1 + shockCond|subid)+
               (-1 + shockCond:RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>% 
              filter(group == 'stress', subid != 'ap173')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(CCN_lh_sig_z) ~ (RT_z + reps) + shockCond + shockCond:RT_z +  
##     (-1 + reps | subid) + (-1 + RT_z | subid) + (-1 + shockCond |  
##     subid) + (-1 + shockCond:RT_z | subid) + (1 | subid)
##    Data: 
## dCleanStandardized_HC_allfmri %>% filter(group == "stress", subid !=  
##     "ap173")
## 
## REML criterion at convergence: 3200.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8259 -0.6616  0.0117  0.6450  3.2091 
## 
## Random effects:
##  Groups   Name                 Variance  Std.Dev.  Corr 
##  subid    reps2                9.012e-04 3.002e-02      
##           reps4                3.752e-04 1.937e-02 -1.00
##  subid.1  RT_z                 0.000e+00 0.000e+00      
##  subid.2  shockCondsafe        0.000e+00 0.000e+00      
##           shockCondthreat      1.999e-15 4.471e-08  NaN 
##  subid.3  shockCondsafe:RT_z   2.812e-02 1.677e-01      
##           shockCondthreat:RT_z 1.057e-03 3.252e-02 -1.00
##  subid.4  (Intercept)          0.000e+00 0.000e+00      
##  Residual                      9.806e-01 9.903e-01      
## Number of obs: 1124, groups:  subid, 21
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept)      3.779e-03  3.039e-02  7.406e+02   0.124   0.9011  
## RT_z             7.902e-02  3.370e-02  3.510e+01   2.345   0.0248 *
## reps1           -1.937e-02  3.111e-02  1.450e+01  -0.623   0.5432  
## shockCond1       2.945e-02  2.960e-02  1.103e+03   0.995   0.3201  
## RT_z:shockCond1  2.647e-02  3.740e-02  2.250e+01   0.708   0.4864  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) RT_z   reps1  shckC1
## RT_z        -0.015                     
## reps1       -0.218  0.085              
## shockCond1  -0.022 -0.018  0.001       
## RT_z:shckC1 -0.022  0.283  0.027  0.001
dCleanStandardized_HC_allfmri %>% filter(group == 'stress',
                                 subid != 'ap173') %>%
  group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 1 x 2
##    group `n()`
##   <fctr> <int>
## 1 stress    21
# is the RT * rep interaction significant?
dCleanStandardized_HC_allfmri %>% 
  group_by(subid, reps) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, reps, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 3 x 3
##    subid   reps count
##   <fctr> <fctr> <dbl>
## 1  ap110      2     3
## 2  ap158      2     2
## 3  ap173      2     2
summary(lmer(scale(CCN_lh_sig_z) ~ group * (RT_z * reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
               (-1 + RT_z:reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>%
              filter(!subid %in% c('ap110', 'ap158', 'ap173'))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_lh_sig_z) ~ group * (RT_z * reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (-1 + RT_z:reps | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(!subid %in% c("ap110",  
##     "ap158", "ap173"))
## 
## REML criterion at convergence: 8182.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8362 -0.6218  0.0163  0.6481  3.7456 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       7.339e-18 2.709e-09  NaN
##  subid.1  RT_z        0.000e+00 0.000e+00     
##  subid.2  RT_z:reps2  3.288e-03 5.734e-02     
##           RT_z:reps4  2.667e-03 5.164e-02 1.00
##  subid.3  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.772e-01 9.885e-01     
## Number of obs: 2888, groups:  subid, 41
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       -3.818e-03  1.940e-02  2.844e+03  -0.197   0.8440    
## group1            -8.760e-03  1.939e-02  2.844e+03  -0.452   0.6515    
## RT_z               1.256e-01  2.121e-02  3.420e+01   5.925 1.05e-06 ***
## reps1              2.135e-02  1.943e-02  2.874e+03   1.099   0.2720    
## shockCond1         1.368e-02  1.843e-02  2.878e+03   0.742   0.4581    
## RT_z:reps1        -8.490e-05  1.927e-02  1.707e+03  -0.004   0.9965    
## group1:RT_z        5.170e-02  2.121e-02  3.420e+01   2.438   0.0201 *  
## group1:reps1       3.917e-02  1.943e-02  2.874e+03   2.016   0.0439 *  
## group1:RT_z:reps1 -1.566e-02  1.927e-02  1.705e+03  -0.813   0.4164    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 RT_z:1 gr1:RT_ grp1:1
## group1      -0.225                                                  
## RT_z        -0.034  0.006                                           
## reps1       -0.199  0.065  0.110                                    
## shockCond1  -0.014  0.008 -0.011 -0.013                             
## RT_z:reps1   0.122 -0.007 -0.131 -0.035  0.011                      
## group1:RT_z  0.006 -0.034 -0.183 -0.008  0.014  0.042               
## group1:rps1  0.065 -0.199 -0.008 -0.224 -0.013  0.007  0.110        
## grp1:RT_z:1 -0.006  0.122  0.042  0.008 -0.020 -0.223 -0.131  -0.034
dCleanStandardized_HC_allfmri %>% filter(!subid %in% c('ap110', 'ap158', 'ap173')) %>%
  group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    20
## 2  stress    21

LH DAN

### DAN
summary(lmer(scale(DAN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_lh_sig_z) ~ group * (RT_z + reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri
## 
## REML criterion at convergence: 8285.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1948 -0.5974 -0.0029  0.6517  3.8551 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.002656 0.05153       
##           reps4       0.001202 0.03467  -1.00
##  subid.1  RT_z        0.002606 0.05105       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.976949 0.98841       
## Number of obs: 2927, groups:  subid, 44
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -6.049e-03  1.923e-02  1.348e+03  -0.315   0.7531    
## group1       -3.567e-03  1.923e-02  1.347e+03  -0.186   0.8528    
## RT_z          1.205e-01  2.070e-02  4.100e+01   5.822 7.75e-07 ***
## reps1         3.215e-02  2.058e-02  4.010e+01   1.562   0.1262    
## shockCond1   -6.863e-03  1.831e-02  2.913e+03  -0.375   0.7078    
## group1:RT_z   5.567e-02  2.070e-02  4.100e+01   2.690   0.0103 *  
## group1:reps1  2.110e-02  2.058e-02  4.010e+01   1.025   0.3115    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 g1:RT_
## group1      -0.232                                   
## RT_z        -0.021  0.004                            
## reps1       -0.215  0.060  0.100                     
## shockCond1  -0.016  0.015 -0.012 -0.014              
## group1:RT_z  0.004 -0.021 -0.189 -0.010  0.011       
## group1:rps1  0.060 -0.216 -0.010 -0.202 -0.015  0.100
# explore interaction of group * rt
summary(lmer(scale(DAN_lh_sig_z) ~ RT_z + reps  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri%>% filter(group == 'control')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_lh_sig_z) ~ RT_z + reps + shockCond + (-1 + reps |  
##     subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(group == "control")
## 
## REML criterion at convergence: 5058.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8479 -0.5884  0.0218  0.6535  3.8557 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       7.296e-16 2.701e-08  NaN
##  subid.1  RT_z        1.630e-03 4.037e-02     
##  subid.2  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.687e-01 9.842e-01     
## Number of obs: 1795, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept) -9.165e-03  2.361e-02  1.778e+03  -0.388   0.6979    
## RT_z         1.765e-01  2.524e-02  2.270e+01   6.995 4.28e-07 ***
## reps1        5.189e-02  2.388e-02  1.782e+03   2.173   0.0299 *  
## shockCond1   8.016e-03  2.326e-02  1.790e+03   0.345   0.7304    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.023              
## reps1      -0.177  0.129       
## shockCond1 -0.002 -0.001 -0.030
summary(lmer(scale(DAN_lh_sig_z) ~ RT_z + reps + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri%>% filter(group == 'stress'),
            control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_lh_sig_z) ~ RT_z + reps + shockCond + (-1 + reps |  
##     subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(group == "stress")
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 3223.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1470 -0.6047 -0.0237  0.6605  3.3117 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.018653 0.13658       
##           reps4       0.007253 0.08517  -1.00
##  subid.1  RT_z        0.006540 0.08087       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.980992 0.99045       
## Number of obs: 1132, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept) -3.012e-03  3.089e-02  1.741e+02  -0.098   0.9224  
## RT_z         6.723e-02  3.514e-02  1.620e+01   1.913   0.0736 .
## reps1        1.184e-02  3.956e-02  1.690e+01   0.299   0.7683  
## shockCond1  -2.963e-02  2.964e-02  1.124e+03  -1.000   0.3176  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.019              
## reps1      -0.291  0.073       
## shockCond1 -0.033 -0.023  0.008
# double check simple effects
# contrasts(dCleanStandardized_HC_allfmri$group) = c(0,1)
# summary(lmer(scale(DAN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + reps|subid)+
#               (-1 + RT_z|subid)+
#               (1 |subid),
#             data=dCleanStandardized_HC_allfmri))
# contrasts(dCleanStandardized_HC_allfmri$group) = c(1,0)
# summary(lmer(scale(DAN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + reps|subid)+
#               (-1 + RT_z|subid)+
#               (1 |subid),
#             data=dCleanStandardized_HC_allfmri))
# contrasts(dCleanStandardized_HC_allfmri$group) = c(1,-1)


# interaction between shockcond and RT on DAN? in stress group
# remove subjs w/trial counts/bin < 6
dCleanStandardized_HC_allfmri %>% filter(group == 'stress') %>% 
  group_by(subid, shockCond) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, shockCond, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 1 x 3
##    subid shockCond count
##   <fctr>    <fctr> <dbl>
## 1  ap173    threat     1
summary(lmer(scale(DAN_lh_sig_z) ~ (RT_z + reps) + shockCond +
               shockCond:RT_z +
              (-1 + RT_z|subid)+
               (-1 + shockCond|subid)+
               (-1 + RT_z:shockCond|subid)+
              (1 |subid), 
              control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5)),
            data=dCleanStandardized_HC_allfmri %>% filter(group == 'stress',
                                                  subid != 'ap173')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(DAN_lh_sig_z) ~ (RT_z + reps) + shockCond + shockCond:RT_z +  
##     (-1 + RT_z | subid) + (-1 + shockCond | subid) + (-1 + RT_z:shockCond |  
##     subid) + (1 | subid)
##    Data: 
## dCleanStandardized_HC_allfmri %>% filter(group == "stress", subid !=  
##     "ap173")
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 3207.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.2500 -0.5890 -0.0251  0.6313  3.2684 
## 
## Random effects:
##  Groups   Name                 Variance  Std.Dev.  Corr 
##  subid    RT_z                 2.250e-03 4.743e-02      
##  subid.1  shockCondsafe        0.000e+00 0.000e+00      
##           shockCondthreat      4.934e-12 2.221e-06  NaN 
##  subid.2  RT_z:shockCondsafe   1.799e-02 1.341e-01      
##           RT_z:shockCondthreat 6.093e-03 7.806e-02 -0.28
##  subid.3  (Intercept)          0.000e+00 0.000e+00      
##  Residual                      9.859e-01 9.929e-01      
## Number of obs: 1124, groups:  subid, 21
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept)      1.112e-03  3.043e-02  1.100e+03   0.037   0.9708  
## RT_z             6.420e-02  3.564e-02  1.540e+01   1.801   0.0913 .
## reps1            9.440e-03  3.067e-02  1.118e+03   0.308   0.7583  
## shockCond1      -2.828e-02  2.972e-02  1.099e+03  -0.951   0.3416  
## RT_z:shockCond1  1.581e-03  3.599e-02  1.700e+01   0.044   0.9655  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) RT_z   reps1  shckC1
## RT_z        -0.015                     
## reps1       -0.214  0.084              
## shockCond1  -0.025 -0.019  0.001       
## RT_z:shckC1 -0.024  0.113  0.026  0.003
dCleanStandardized_HC_allfmri %>% filter(group == 'stress',
                                 subid != 'ap173') %>%
  group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 1 x 2
##    group `n()`
##   <fctr> <int>
## 1 stress    21
# is the RT * rep interaction significant?
dCleanStandardized_HC_allfmri %>% 
  group_by(subid, reps) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, reps, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 3 x 3
##    subid   reps count
##   <fctr> <fctr> <dbl>
## 1  ap110      2     3
## 2  ap158      2     2
## 3  ap173      2     2
summary(lmer(scale(DAN_lh_sig_z) ~ group * (RT_z * reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
               (-1 + RT_z:reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>%
              filter(!subid %in% c('ap110', 'ap158', 'ap173'))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_lh_sig_z) ~ group * (RT_z * reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (-1 + RT_z:reps | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(!subid %in% c("ap110",  
##     "ap158", "ap173"))
## 
## REML criterion at convergence: 8192.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1885 -0.5911 -0.0067  0.6509  3.8416 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.002485 0.04985       
##           reps4       0.001160 0.03405  -1.00
##  subid.1  RT_z        0.000000 0.00000       
##  subid.2  RT_z:reps2  0.002142 0.04628       
##           RT_z:reps4  0.002753 0.05247  1.00 
##  subid.3  (Intercept) 0.000000 0.00000       
##  Residual             0.979362 0.98963       
## Number of obs: 2888, groups:  subid, 41
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       -4.890e-03  1.948e-02  1.467e+03  -0.251   0.8018    
## group1            -3.272e-03  1.948e-02  1.467e+03  -0.168   0.8666    
## RT_z               1.144e-01  2.089e-02  4.210e+01   5.475 2.23e-06 ***
## reps1              3.140e-02  2.066e-02  4.000e+01   1.520   0.1365    
## shockCond1        -6.288e-03  1.845e-02  2.872e+03  -0.341   0.7333    
## RT_z:reps1         6.934e-03  1.927e-02  2.593e+03   0.360   0.7190    
## group1:RT_z        5.388e-02  2.089e-02  4.210e+01   2.579   0.0135 *  
## group1:reps1       1.993e-02  2.066e-02  4.000e+01   0.965   0.3405    
## group1:RT_z:reps1 -2.734e-03  1.927e-02  2.592e+03  -0.142   0.8872    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 RT_z:1 gr1:RT_ grp1:1
## group1      -0.223                                                  
## RT_z        -0.035  0.007                                           
## reps1       -0.211  0.061  0.105                                    
## shockCond1  -0.014  0.008 -0.011 -0.012                             
## RT_z:reps1   0.123 -0.007 -0.111 -0.033  0.011                      
## group1:RT_z  0.006 -0.035 -0.189 -0.008  0.014  0.043               
## group1:rps1  0.061 -0.211 -0.008 -0.198 -0.013  0.007  0.105        
## grp1:RT_z:1 -0.006  0.123  0.043  0.007 -0.020 -0.223 -0.111  -0.033

Plot combined lh networks

## collapse
dm_avg = dm_allfmri %>% filter(pcorr == 1) %>%
  group_by(subid) %>%
  mutate(rt_quintile = ntile(respRT, 5)) %>%
  group_by(subid, group, rt_quintile) %>%
  summarise(ccn = mean_(CCN_lh_sig), 
            dan = mean_(DAN_lh_sig), 
            count = n()) %>% 
  gather(key = 'network', value = 'signal', ccn:dan) %>%
  mutate(network = replace(network, network=='ccn', 'CCN'),
         network = replace(network, network=='dan', 'DAN'))
  
dfwc = summarySEwithin(dm_avg, measurevar="signal", 
                       withinvars=c("rt_quintile", "network"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: rt_quintile, network
dfwc
##      group rt_quintile network  N     signal signal_norm         sd
## 1  control           1     CCN 22 0.03230130  0.04668815 0.06275263
## 2  control           1     DAN 22 0.01262089  0.02700774 0.07062237
## 3  control           2     CCN 22 0.07582863  0.09021548 0.07688394
## 4  control           2     DAN 22 0.04543842  0.05982528 0.06851596
## 5  control           3     CCN 22 0.14757958  0.16196643 0.09290254
## 6  control           3     DAN 22 0.10225941  0.11664626 0.08514998
## 7  control           4     CCN 22 0.14597583  0.16036268 0.10035884
## 8  control           4     DAN 22 0.10304145  0.11742831 0.08069073
## 9  control           5     CCN 22 0.19266350  0.20705035 0.07902218
## 10 control           5     DAN 22 0.15007843  0.16446528 0.06707180
## 11  stress           1     CCN 22 0.10998110  0.09559425 0.17304944
## 12  stress           1     DAN 22 0.07594667  0.06155981 0.13707953
## 13  stress           2     CCN 22 0.12189648  0.10750963 0.13456509
## 14  stress           2     DAN 22 0.08136196  0.06697511 0.11640587
## 15  stress           3     CCN 22 0.14089084  0.12650399 0.10618655
## 16  stress           3     DAN 22 0.11177971  0.09739286 0.11820127
## 17  stress           4     CCN 22 0.21731931  0.20293246 0.13782212
## 18  stress           4     DAN 22 0.15811092  0.14372407 0.14472055
## 19  stress           5     CCN 22 0.15770078  0.14331393 0.10203830
## 20  stress           5     DAN 22 0.12053672  0.10614987 0.13673281
##            se         ci
## 1  0.01337891 0.02782296
## 2  0.01505674 0.03131220
## 3  0.01639171 0.03408843
## 4  0.01460765 0.03037828
## 5  0.01980689 0.04119068
## 6  0.01815404 0.03775338
## 7  0.02139658 0.04449662
## 8  0.01720332 0.03577626
## 9  0.01684759 0.03503647
## 10 0.01429976 0.02973797
## 11 0.03689427 0.07672582
## 12 0.02922545 0.06077766
## 13 0.02868937 0.05966282
## 14 0.02481781 0.05161147
## 15 0.02263905 0.04708048
## 16 0.02520060 0.05240751
## 17 0.02938377 0.06110690
## 18 0.03085452 0.06416550
## 19 0.02175464 0.04524125
## 20 0.02915153 0.06062393
ann_text <- data.frame(rt_quintile = c(3.2, 1.8), 
                       signal = c(0.08, .18),
                       group=c('control', 'stress'),
                       lab=c("control", "stress"),
                       network = factor(c('CCN', 'CCN'), 
                                      levels = c("CCN", "DAN")))

p2 = ggplot(dfwc, aes(x=rt_quintile, y=signal, group=group, color=group)) +
  facet_grid(.~network)+
    geom_line(position=pos_dodge, size=1) +
    geom_errorbar(width=0, aes(ymin=signal-se, 
                               ymax=signal+se), size=1, position=pos_dodge) +
    geom_point(size=3, position=pos_dodge) + 
  ylab('Percent signal change')+
  xlab('RT (quintiles)')+
  ylim(-.015, .25)+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL)) +
  theme_classic(base_size=14) +
  geom_text(data = ann_text, aes(label=lab)) +
  theme(legend.title=element_blank(), 
        legend.position="none",
        strip.text = element_text(size=14),
        strip.background = element_rect(colour="white", fill="white"))
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/respRTXfrontoparietalLH_quintile_HCrecollection_allfmri.jpg',
       dpi=600, width = 4.7, height=2.5)

Plot combined lh networks, full names

## collapse
dm_avg = dm_allfmri %>% filter(pcorr == 1) %>%
  group_by(subid) %>%
  mutate(rt_quintile = ntile(respRT, 5)) %>%
  group_by(subid, group, rt_quintile) %>%
  summarise(ccn = mean_(CCN_lh_sig), 
            dan = mean_(DAN_lh_sig), 
            count = n()) %>% 
  gather(key = 'network', value = 'signal', ccn:dan) %>%
  mutate(network = replace(network, network=='ccn', 'Cognitive control'),
         network = replace(network, network=='dan', 'Dorsal attention'))
  
dfwc = summarySEwithin(dm_avg, measurevar="signal", 
                       withinvars=c("rt_quintile", "network"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: rt_quintile, network
dfwc
##      group rt_quintile           network  N     signal signal_norm
## 1  control           1 Cognitive control 22 0.03230130  0.04668815
## 2  control           1  Dorsal attention 22 0.01262089  0.02700774
## 3  control           2 Cognitive control 22 0.07582863  0.09021548
## 4  control           2  Dorsal attention 22 0.04543842  0.05982528
## 5  control           3 Cognitive control 22 0.14757958  0.16196643
## 6  control           3  Dorsal attention 22 0.10225941  0.11664626
## 7  control           4 Cognitive control 22 0.14597583  0.16036268
## 8  control           4  Dorsal attention 22 0.10304145  0.11742831
## 9  control           5 Cognitive control 22 0.19266350  0.20705035
## 10 control           5  Dorsal attention 22 0.15007843  0.16446528
## 11  stress           1 Cognitive control 22 0.10998110  0.09559425
## 12  stress           1  Dorsal attention 22 0.07594667  0.06155981
## 13  stress           2 Cognitive control 22 0.12189648  0.10750963
## 14  stress           2  Dorsal attention 22 0.08136196  0.06697511
## 15  stress           3 Cognitive control 22 0.14089084  0.12650399
## 16  stress           3  Dorsal attention 22 0.11177971  0.09739286
## 17  stress           4 Cognitive control 22 0.21731931  0.20293246
## 18  stress           4  Dorsal attention 22 0.15811092  0.14372407
## 19  stress           5 Cognitive control 22 0.15770078  0.14331393
## 20  stress           5  Dorsal attention 22 0.12053672  0.10614987
##            sd         se         ci
## 1  0.06275263 0.01337891 0.02782296
## 2  0.07062237 0.01505674 0.03131220
## 3  0.07688394 0.01639171 0.03408843
## 4  0.06851596 0.01460765 0.03037828
## 5  0.09290254 0.01980689 0.04119068
## 6  0.08514998 0.01815404 0.03775338
## 7  0.10035884 0.02139658 0.04449662
## 8  0.08069073 0.01720332 0.03577626
## 9  0.07902218 0.01684759 0.03503647
## 10 0.06707180 0.01429976 0.02973797
## 11 0.17304944 0.03689427 0.07672582
## 12 0.13707953 0.02922545 0.06077766
## 13 0.13456509 0.02868937 0.05966282
## 14 0.11640587 0.02481781 0.05161147
## 15 0.10618655 0.02263905 0.04708048
## 16 0.11820127 0.02520060 0.05240751
## 17 0.13782212 0.02938377 0.06110690
## 18 0.14472055 0.03085452 0.06416550
## 19 0.10203830 0.02175464 0.04524125
## 20 0.13673281 0.02915153 0.06062393
p2 = ggplot(dfwc, aes(x=rt_quintile, y=signal, group=group, color=group)) +
  facet_grid(.~network)+
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=signal-se, 
                               ymax=signal+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('Percent signal change')+
  xlab('RT (quintiles)')+
  ylim(-.015, .25)+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/respRTXfrontoparietalLH_quintile_HCrecollection_allfmri_fullnames.jpg',
       dpi=300, width = 8, height=4)
p2

Bilateral networks

CCN
summary(lmer(scale(CCN_sig_z) ~ group * (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_sig_z) ~ group * (RT_z + reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri
## 
## REML criterion at convergence: 8305.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9353 -0.6196  0.0292  0.6526  3.6600 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       1.602e-16 1.266e-08  NaN
##  subid.1  RT_z        2.995e-03 5.473e-02     
##  subid.2  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.850e-01 9.925e-01     
## Number of obs: 2927, groups:  subid, 44
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -4.562e-03  1.923e-02  2.881e+03  -0.237 0.812512    
## group1       -6.185e-03  1.923e-02  2.881e+03  -0.322 0.747754    
## RT_z          8.793e-02  2.099e-02  3.270e+01   4.189 0.000199 ***
## reps1         2.588e-02  1.940e-02  2.915e+03   1.334 0.182342    
## shockCond1    9.953e-03  1.838e-02  2.919e+03   0.542 0.588137    
## group1:RT_z   5.584e-02  2.099e-02  3.270e+01   2.660 0.012010 *  
## group1:reps1  3.495e-02  1.940e-02  2.915e+03   1.802 0.071701 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 g1:RT_
## group1      -0.234                                   
## RT_z        -0.021  0.004                            
## reps1       -0.200  0.064  0.106                     
## shockCond1  -0.016  0.014 -0.012 -0.015              
## group1:RT_z  0.004 -0.021 -0.185 -0.010  0.011       
## group1:rps1  0.064 -0.201 -0.009 -0.228 -0.014  0.106
summary(lmer(scale(CCN_sig_z) ~ RT_z + reps  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri%>% filter(group == 'control')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(CCN_sig_z) ~ RT_z + reps + shockCond + (-1 + reps | subid) +  
##     (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(group == "control")
## 
## REML criterion at convergence: 5075.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9481 -0.6062  0.0407  0.6464  3.6747 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       6.711e-22 2.591e-11  NaN
##  subid.1  RT_z        0.000e+00 0.000e+00     
##  subid.2  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.794e-01 9.897e-01     
## Number of obs: 1795, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept) -1.049e-02  2.373e-02  1.791e+03  -0.442   0.6586    
## RT_z         1.453e-01  2.357e-02  1.791e+03   6.165 8.67e-10 ***
## reps1        5.975e-02  2.398e-02  1.791e+03   2.491   0.0128 *  
## shockCond1   7.280e-04  2.337e-02  1.791e+03   0.031   0.9752    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.025              
## reps1      -0.177  0.142       
## shockCond1 -0.002 -0.002 -0.029
summary(lmer(scale(CCN_sig_z) ~ RT_z + reps + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>% filter(group == 'stress'),
            control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(CCN_sig_z) ~ RT_z + reps + shockCond + (-1 + reps | subid) +  
##     (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(group == "stress")
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 3227.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9361 -0.6480  0.0135  0.6603  3.1967 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.006532 0.08082       
##           reps4       0.002673 0.05170  -1.00
##  subid.1  RT_z        0.011213 0.10589       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.986739 0.99335       
## Number of obs: 1132, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)  8.835e-04  3.052e-02  3.673e+02   0.029    0.977
## RT_z         3.132e-02  3.835e-02  1.670e+01   0.817    0.426
## reps1       -8.530e-03  3.419e-02  1.720e+01  -0.250    0.806
## shockCond1   2.641e-02  2.971e-02  1.126e+03   0.889    0.374
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.018              
## reps1      -0.245  0.076       
## shockCond1 -0.032 -0.021  0.005
# interaction between shockcond and RT on CCN? in stress group
# remove subjs w/trial counts/bin < 6
dCleanStandardized_HC_allfmri %>% filter(group == 'stress') %>% 
  group_by(subid, shockCond) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, shockCond, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 1 x 3
##    subid shockCond count
##   <fctr>    <fctr> <dbl>
## 1  ap173    threat     1
dCleanStandardized_HC_allfmri %>% filter(group == 'stress') %>% 
  group_by(subid, shockCond) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, shockCond, fill = list(count= 0))
## # A tibble: 44 x 3
##     subid shockCond count
##    <fctr>    <fctr> <dbl>
##  1  ap150      safe    33
##  2  ap150    threat    33
##  3  ap152      safe    18
##  4  ap152    threat    22
##  5  ap153      safe    17
##  6  ap153    threat    14
##  7  ap154      safe    20
##  8  ap154    threat    22
##  9  ap155      safe    27
## 10  ap155    threat    11
## # ... with 34 more rows
summary(lmer(scale(CCN_sig_z) ~ (RT_z + reps) + shockCond +
               shockCond:RT_z +
              (-1 + RT_z|subid)+ # remove reps random slope to converge
               (-1 + shockCond|subid)+
               (-1 + shockCond:RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>% filter(group == 'stress',
                                                  subid != 'ap173'),
            control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_sig_z) ~ (RT_z + reps) + shockCond + shockCond:RT_z +  
##     (-1 + RT_z | subid) + (-1 + shockCond | subid) + (-1 + shockCond:RT_z |  
##     subid) + (1 | subid)
##    Data: 
## dCleanStandardized_HC_allfmri %>% filter(group == "stress", subid !=  
##     "ap173")
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 3207.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9475 -0.6394  0.0010  0.6419  3.2022 
## 
## Random effects:
##  Groups   Name                 Variance  Std.Dev.  Corr
##  subid    RT_z                 2.789e-03 5.281e-02     
##  subid.1  shockCondsafe        0.000e+00 0.000e+00     
##           shockCondthreat      1.147e-10 1.071e-05  NaN
##  subid.2  shockCondsafe:RT_z   2.672e-02 1.635e-01     
##           shockCondthreat:RT_z 9.376e-06 3.062e-03 1.00
##  subid.3  (Intercept)          1.525e-10 1.235e-05     
##  Residual                      9.860e-01 9.930e-01     
## Number of obs: 1124, groups:  subid, 21
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)      2.845e-03  3.040e-02  1.099e+03   0.094    0.925
## RT_z             3.392e-02  3.746e-02  1.530e+01   0.905    0.379
## reps1           -1.177e-02  3.066e-02  1.116e+03  -0.384    0.701
## shockCond1       2.658e-02  2.973e-02  1.104e+03   0.894    0.371
## RT_z:shockCond1  1.015e-02  3.510e-02  2.260e+01   0.289    0.775
## 
## Correlation of Fixed Effects:
##             (Intr) RT_z   reps1  shckC1
## RT_z        -0.015                     
## reps1       -0.214  0.079              
## shockCond1  -0.022 -0.017  0.001       
## RT_z:shckC1 -0.023  0.264  0.025  0.003
dCleanStandardized_HC_allfmri %>% filter(group == 'stress',
                                 subid != 'ap173') %>%
  group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 1 x 2
##    group `n()`
##   <fctr> <int>
## 1 stress    21
# is the RT * rep interaction significant?
dCleanStandardized_HC_allfmri %>% 
  group_by(subid, reps) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, reps, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 3 x 3
##    subid   reps count
##   <fctr> <fctr> <dbl>
## 1  ap110      2     3
## 2  ap158      2     2
## 3  ap173      2     2
summary(lmer(scale(CCN_sig_z) ~ group * (RT_z * reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (-1 + RT_z:reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>%
              filter(!subid %in% c('ap110', 'ap158', 'ap173'))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_sig_z) ~ group * (RT_z * reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (-1 + RT_z:reps | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(!subid %in% c("ap110",  
##     "ap158", "ap173"))
## 
## REML criterion at convergence: 8207.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9196 -0.6222  0.0233  0.6453  3.6728 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       7.027e-16 2.651e-08  NaN
##  subid.1  RT_z        0.000e+00 0.000e+00     
##  subid.2  RT_z:reps2  4.627e-03 6.802e-02     
##           RT_z:reps4  2.093e-03 4.575e-02 1.00
##  subid.3  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.856e-01 9.928e-01     
## Number of obs: 2888, groups:  subid, 41
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       -5.920e-03  1.948e-02  2.842e+03  -0.304 0.761216    
## group1            -9.206e-03  1.948e-02  2.842e+03  -0.473 0.636531    
## RT_z               8.709e-02  2.147e-02  2.950e+01   4.057 0.000334 ***
## reps1              2.344e-02  1.952e-02  2.874e+03   1.201 0.229785    
## shockCond1         9.139e-03  1.851e-02  2.878e+03   0.494 0.621549    
## RT_z:reps1        -1.145e-02  1.946e-02  4.965e+02  -0.589 0.556408    
## group1:RT_z        5.566e-02  2.147e-02  2.950e+01   2.593 0.014664 *  
## group1:reps1       3.475e-02  1.952e-02  2.874e+03   1.781 0.075095 .  
## group1:RT_z:reps1 -2.329e-02  1.946e-02  4.960e+02  -1.197 0.231973    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 RT_z:1 gr1:RT_ grp1:1
## group1      -0.225                                                  
## RT_z        -0.034  0.007                                           
## reps1       -0.199  0.065  0.109                                    
## shockCond1  -0.014  0.008 -0.011 -0.013                             
## RT_z:reps1   0.121 -0.007 -0.162 -0.034  0.011                      
## group1:RT_z  0.007 -0.034 -0.180 -0.008  0.014  0.042               
## group1:rps1  0.065 -0.199 -0.008 -0.224 -0.013  0.007  0.108        
## grp1:RT_z:1 -0.007  0.121  0.042  0.008 -0.020 -0.221 -0.162  -0.034
dCleanStandardized_HC_allfmri %>% filter(!subid %in% c('ap110', 'ap158', 'ap173')) %>%
  group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    20
## 2  stress    21
DAN
summary(lmer(scale(DAN_sig_z) ~ group * (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_sig_z) ~ group * (RT_z + reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri
## 
## REML criterion at convergence: 8307.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9994 -0.6088  0.0075  0.6615  3.6197 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.005026 0.07089       
##           reps4       0.002307 0.04803  -1.00
##  subid.1  RT_z        0.003214 0.05669       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.982744 0.99133       
## Number of obs: 2927, groups:  subid, 44
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -7.918e-03  1.934e-02  1.002e+03  -0.409   0.6824    
## group1       -2.928e-03  1.934e-02  1.001e+03  -0.151   0.8797    
## RT_z          9.258e-02  2.114e-02  3.960e+01   4.378  8.5e-05 ***
## reps1         4.025e-02  2.170e-02  3.920e+01   1.855   0.0711 .  
## shockCond1   -5.259e-03  1.837e-02  2.911e+03  -0.286   0.7747    
## group1:RT_z   4.297e-02  2.114e-02  3.960e+01   2.032   0.0489 *  
## group1:reps1  1.893e-02  2.170e-02  3.920e+01   0.872   0.3884    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 g1:RT_
## group1      -0.231                                   
## RT_z        -0.020  0.004                            
## reps1       -0.226  0.057  0.093                     
## shockCond1  -0.016  0.015 -0.012 -0.013              
## group1:RT_z  0.004 -0.020 -0.183 -0.011  0.011       
## group1:rps1  0.057 -0.226 -0.011 -0.183 -0.016  0.093
# make sure it holds w/correlated int/slope -- reps RE changes...
fit2 = lmer(scale(DAN_sig_z) ~ group * (RT_z + reps)  + shockCond +
              (1+ reps + RT_z|subid), 
            data=dCleanStandardized_HC_allfmri)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control
## $checkConv, : Model failed to converge with max|grad| = 0.00690252 (tol =
## 0.002, component 1)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model is nearly unidentifiable: large eigenvalue ratio
##  - Rescale variables?
coef(fit2)
## $subid
##         (Intercept)       group1       RT_z        reps1   shockCond1
## ap100 -0.0047793722 -0.002972828 0.06788118  0.023327370 -0.005342502
## ap101 -0.0071882063 -0.002972828 0.12140446  0.035917601 -0.005342502
## ap102 -0.0051616031 -0.002972828 0.09144731  0.025325173 -0.005342502
## ap103 -0.0081557719 -0.002972828 0.05560575  0.040974767 -0.005342502
## ap104 -0.0082389464 -0.002972828 0.04855497  0.041409495 -0.005342502
## ap105 -0.0081383152 -0.002972828 0.07862580  0.040883527 -0.005342502
## ap107 -0.0135281085 -0.002972828 0.13103518  0.069054309 -0.005342502
## ap108 -0.0094598920 -0.002972828 0.08912384  0.047790999 -0.005342502
## ap109 -0.0100887151 -0.002972828 0.09268312  0.051077663 -0.005342502
## ap110 -0.0129180653 -0.002972828 0.11615379  0.065865802 -0.005342502
## ap111 -0.0094956199 -0.002972828 0.08446214  0.047977738 -0.005342502
## ap113 -0.0060401448 -0.002972828 0.10943114  0.029917038 -0.005342502
## ap114 -0.0084654106 -0.002972828 0.06131887  0.042593153 -0.005342502
## ap115 -0.0099293504 -0.002972828 0.09976679  0.050244713 -0.005342502
## ap116  0.0061253441 -0.002972828 0.09844421 -0.033668209 -0.005342502
## ap117 -0.0063121393 -0.002972828 0.06464274  0.031338670 -0.005342502
## ap118 -0.0073155874 -0.002972828 0.10786519  0.036583383 -0.005342502
## ap119 -0.0088422534 -0.002972828 0.10302320  0.044562794 -0.005342502
## ap120 -0.0104587544 -0.002972828 0.08309731  0.053011745 -0.005342502
## ap121 -0.0046319626 -0.002972828 0.07610042  0.022556906 -0.005342502
## ap122 -0.0176893231 -0.002972828 0.15385972  0.090803691 -0.005342502
## ap150  0.0045216837 -0.002972828 0.06173774 -0.025286373 -0.005342502
## ap152 -0.0090462696 -0.002972828 0.11287340  0.045629123 -0.005342502
## ap153 -0.0043307945 -0.002972828 0.11195998  0.020982793 -0.005342502
## ap154 -0.0094305433 -0.002972828 0.04818004  0.047637603 -0.005342502
## ap155 -0.0028248014 -0.002972828 0.05212806  0.013111433 -0.005342502
## ap157 -0.0163377662 -0.002972828 0.08101901  0.083739521 -0.005342502
## ap158 -0.0065062295 -0.002972828 0.10530388  0.032353119 -0.005342502
## ap159 -0.0129263748 -0.002972828 0.10840311  0.065909233 -0.005342502
## ap160 -0.0048110112 -0.002972828 0.06830421  0.023492737 -0.005342502
## ap161 -0.0009353132 -0.002972828 0.08473583  0.003235662 -0.005342502
## ap162 -0.0081486747 -0.002972828 0.11225711  0.040937672 -0.005342502
## ap163 -0.0027542434 -0.002972828 0.07679163  0.012742648 -0.005342502
## ap164 -0.0107556412 -0.002972828 0.08409981  0.054563480 -0.005342502
## ap165 -0.0032368939 -0.002972828 0.08932587  0.015265313 -0.005342502
## ap166 -0.0157197818 -0.002972828 0.15064282  0.080509508 -0.005342502
## ap167 -0.0133477078 -0.002972828 0.09219483  0.068111410 -0.005342502
## ap168 -0.0055459546 -0.002972828 0.08164131  0.027334059 -0.005342502
## ap169 -0.0204576888 -0.002972828 0.12048611  0.105273083 -0.005342502
## ap170 -0.0042336529 -0.002972828 0.09983895  0.020475064 -0.005342502
## ap171 -0.0105410584 -0.002972828 0.11075443  0.053441922 -0.005342502
## ap172 -0.0098658217 -0.002972828 0.08087288  0.049912669 -0.005342502
## ap173 -0.0085016584 -0.002972828 0.10344073  0.042782609 -0.005342502
## ap174 -0.0079884593 -0.002972828 0.10814315  0.040100276 -0.005342502
##       group1:RT_z group1:reps1
## ap100  0.04295962   0.01892237
## ap101  0.04295962   0.01892237
## ap102  0.04295962   0.01892237
## ap103  0.04295962   0.01892237
## ap104  0.04295962   0.01892237
## ap105  0.04295962   0.01892237
## ap107  0.04295962   0.01892237
## ap108  0.04295962   0.01892237
## ap109  0.04295962   0.01892237
## ap110  0.04295962   0.01892237
## ap111  0.04295962   0.01892237
## ap113  0.04295962   0.01892237
## ap114  0.04295962   0.01892237
## ap115  0.04295962   0.01892237
## ap116  0.04295962   0.01892237
## ap117  0.04295962   0.01892237
## ap118  0.04295962   0.01892237
## ap119  0.04295962   0.01892237
## ap120  0.04295962   0.01892237
## ap121  0.04295962   0.01892237
## ap122  0.04295962   0.01892237
## ap150  0.04295962   0.01892237
## ap152  0.04295962   0.01892237
## ap153  0.04295962   0.01892237
## ap154  0.04295962   0.01892237
## ap155  0.04295962   0.01892237
## ap157  0.04295962   0.01892237
## ap158  0.04295962   0.01892237
## ap159  0.04295962   0.01892237
## ap160  0.04295962   0.01892237
## ap161  0.04295962   0.01892237
## ap162  0.04295962   0.01892237
## ap163  0.04295962   0.01892237
## ap164  0.04295962   0.01892237
## ap165  0.04295962   0.01892237
## ap166  0.04295962   0.01892237
## ap167  0.04295962   0.01892237
## ap168  0.04295962   0.01892237
## ap169  0.04295962   0.01892237
## ap170  0.04295962   0.01892237
## ap171  0.04295962   0.01892237
## ap172  0.04295962   0.01892237
## ap173  0.04295962   0.01892237
## ap174  0.04295962   0.01892237
## 
## attr(,"class")
## [1] "coef.mer"
summary(fit2)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(DAN_sig_z) ~ group * (RT_z + reps) + shockCond + (1 + reps +  
##     RT_z | subid)
##    Data: dCleanStandardized_HC_allfmri
## 
## REML criterion at convergence: 8307.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9981 -0.6100  0.0059  0.6624  3.6194 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr       
##  subid    (Intercept) 0.0001381 0.01175             
##           reps1       0.0037740 0.06143  -1.00      
##           RT_z        0.0034264 0.05854  -0.31  0.31
##  Residual             0.9825694 0.99125             
## Number of obs: 2927, groups:  subid, 44
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -8.055e-03  1.935e-02  9.742e+02  -0.416   0.6773    
## group1       -2.973e-03  1.935e-02  9.733e+02  -0.154   0.8779    
## RT_z          9.272e-02  2.127e-02  3.900e+01   4.359 9.24e-05 ***
## reps1         4.045e-02  2.184e-02  3.900e+01   1.852   0.0716 .  
## shockCond1   -5.343e-03  1.837e-02  2.911e+03  -0.291   0.7712    
## group1:RT_z   4.296e-02  2.127e-02  3.900e+01   2.020   0.0503 .  
## group1:reps1  1.892e-02  2.184e-02  3.900e+01   0.866   0.3915    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 g1:RT_
## group1      -0.231                                   
## RT_z        -0.035  0.005                            
## reps1       -0.227  0.057  0.156                     
## shockCond1  -0.016  0.015 -0.011 -0.013              
## group1:RT_z  0.005 -0.035 -0.182 -0.011  0.010       
## group1:rps1  0.057 -0.228 -0.011 -0.182 -0.015  0.156
## convergence code: 0
## Model failed to converge with max|grad| = 0.00690252 (tol = 0.002, component 1)
## Model is nearly unidentifiable: large eigenvalue ratio
##  - Rescale variables?
summary(lmer(scale(DAN_sig_z) ~ RT_z + reps  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri%>% filter(group == 'control')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(DAN_sig_z) ~ RT_z + reps + shockCond + (-1 + reps | subid) +  
##     (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(group == "control")
## 
## REML criterion at convergence: 5079.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9821 -0.6124  0.0222  0.6621  3.6206 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  subid    reps2       3.420e-14 1.849e-07      
##           reps4       1.073e-14 1.036e-07 -1.00
##  subid.1  RT_z        3.038e-03 5.512e-02      
##  subid.2  (Intercept) 0.000e+00 0.000e+00      
##  Residual             9.792e-01 9.895e-01      
## Number of obs: 1795, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)   -0.01012    0.02373 1776.80000  -0.427   0.6697    
## RT_z           0.13640    0.02678   21.70000   5.094 4.39e-05 ***
## reps1          0.05725    0.02404 1785.20000   2.382   0.0173 *  
## shockCond1     0.01059    0.02339 1789.10000   0.453   0.6507    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.021              
## reps1      -0.178  0.121       
## shockCond1 -0.002 -0.001 -0.030
summary(lmer(scale(DAN_sig_z) ~ RT_z + reps + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>% filter(group == 'stress'),
            control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(DAN_sig_z) ~ RT_z + reps + shockCond + (-1 + reps | subid) +  
##     (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(group == "stress")
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 3223.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9479 -0.6095 -0.0157  0.6520  3.4683 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.024700 0.15716       
##           reps4       0.009742 0.09870  -1.00
##  subid.1  RT_z        0.005569 0.07463       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.979902 0.98990       
## Number of obs: 1132, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)
## (Intercept) -5.413e-03  3.106e-02  1.478e+02  -0.174    0.862
## RT_z         5.250e-02  3.443e-02  1.420e+01   1.525    0.149
## reps1        2.187e-02  4.202e-02  1.800e+01   0.520    0.609
## shockCond1  -3.009e-02  2.963e-02  1.123e+03  -1.016    0.310
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.020              
## reps1      -0.308  0.070       
## shockCond1 -0.033 -0.023  0.008
# interaction between shockcond and RT on DAN? in stress group
# remove subjs w/trial counts/bin < 6
dCleanStandardized_HC_allfmri %>% filter(group == 'stress') %>% 
  group_by(subid, shockCond) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, shockCond, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 1 x 3
##    subid shockCond count
##   <fctr>    <fctr> <dbl>
## 1  ap173    threat     1
summary(lmer(scale(DAN_sig_z) ~ (RT_z + reps) + shockCond +
               shockCond:RT_z +
              (-1 + reps|subid)+ 
              (-1 + RT_z|subid)+ 
               (-1 + shockCond|subid)+
               (-1 + shockCond:RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>% filter(group == 'stress',
                                                  subid != 'ap173'),
            control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_sig_z) ~ (RT_z + reps) + shockCond + shockCond:RT_z +  
##     (-1 + reps | subid) + (-1 + RT_z | subid) + (-1 + shockCond |  
##     subid) + (-1 + shockCond:RT_z | subid) + (1 | subid)
##    Data: 
## dCleanStandardized_HC_allfmri %>% filter(group == "stress", subid !=  
##     "ap173")
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 3205.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9549 -0.6118 -0.0063  0.6491  3.4821 
## 
## Random effects:
##  Groups   Name                 Variance  Std.Dev.  Corr 
##  subid    reps2                2.501e-02 1.581e-01      
##           reps4                9.989e-03 9.995e-02 -1.00
##  subid.1  RT_z                 3.924e-03 6.264e-02      
##  subid.2  shockCondsafe        5.656e-11 7.521e-06      
##           shockCondthreat      4.449e-11 6.670e-06 -1.00
##  subid.3  shockCondsafe:RT_z   1.064e-02 1.032e-01      
##           shockCondthreat:RT_z 6.968e-04 2.640e-02 -1.00
##  subid.4  (Intercept)          0.000e+00 0.000e+00      
##  Residual                      9.770e-01 9.884e-01      
## Number of obs: 1124, groups:  subid, 21
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)     -3.339e-03  3.116e-02  1.467e+02  -0.107    0.915
## RT_z             5.069e-02  3.450e-02  1.320e+01   1.469    0.165
## reps1            2.058e-02  4.244e-02  1.710e+01   0.485    0.634
## shockCond1      -2.927e-02  2.968e-02  1.097e+03  -0.986    0.324
## RT_z:shockCond1 -1.584e-02  3.352e-02  1.730e+01  -0.473    0.642
## 
## Correlation of Fixed Effects:
##             (Intr) RT_z   reps1  shckC1
## RT_z        -0.017                     
## reps1       -0.306  0.066              
## shockCond1  -0.027 -0.020  0.010       
## RT_z:shckC1 -0.022  0.111  0.023  0.005
dCleanStandardized_HC_allfmri %>% filter(group == 'stress',
                                 subid != 'ap173') %>%
  group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 1 x 2
##    group `n()`
##   <fctr> <int>
## 1 stress    21
# is the RT * rep interaction significant?
dCleanStandardized_HC_allfmri %>% 
  group_by(subid, reps) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, reps, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 3 x 3
##    subid   reps count
##   <fctr> <fctr> <dbl>
## 1  ap110      2     3
## 2  ap158      2     2
## 3  ap173      2     2
summary(lmer(scale(DAN_sig_z) ~ group * (RT_z * reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (-1 + RT_z:reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>%
              filter(!subid %in% c('ap110', 'ap158', 'ap173'))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_sig_z) ~ group * (RT_z * reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (-1 + RT_z:reps | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(!subid %in% c("ap110",  
##     "ap158", "ap173"))
## 
## REML criterion at convergence: 8213.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9938 -0.6076  0.0069  0.6602  3.6105 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.004831 0.06950       
##           reps4       0.002293 0.04788  -1.00
##  subid.1  RT_z        0.000000 0.00000       
##  subid.2  RT_z:reps2  0.002352 0.04850       
##           RT_z:reps4  0.003711 0.06092  1.00 
##  subid.3  (Intercept) 0.000000 0.00000       
##  Residual             0.984821 0.99238       
## Number of obs: 2888, groups:  subid, 41
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       -7.147e-03  1.959e-02  1.100e+03  -0.365 0.715301    
## group1            -2.905e-03  1.959e-02  1.100e+03  -0.148 0.882124    
## RT_z               8.662e-02  2.131e-02  4.110e+01   4.065 0.000212 ***
## reps1              3.905e-02  2.180e-02  3.880e+01   1.792 0.080979 .  
## shockCond1        -5.661e-03  1.852e-02  2.870e+03  -0.306 0.759812    
## RT_z:reps1         2.785e-03  1.935e-02  1.789e+03   0.144 0.885566    
## group1:RT_z        4.129e-02  2.131e-02  4.110e+01   1.938 0.059552 .  
## group1:reps1       1.796e-02  2.180e-02  3.880e+01   0.824 0.415029    
## group1:RT_z:reps1 -3.808e-03  1.935e-02  1.790e+03  -0.197 0.844023    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 RT_z:1 gr1:RT_ grp1:1
## group1      -0.223                                                  
## RT_z        -0.034  0.007                                           
## reps1       -0.220  0.058  0.099                                    
## shockCond1  -0.015  0.008 -0.011 -0.011                             
## RT_z:reps1   0.122 -0.007 -0.097 -0.031  0.011                      
## group1:RT_z  0.007 -0.034 -0.182 -0.009  0.014  0.043               
## group1:rps1  0.058 -0.221 -0.008 -0.178 -0.014  0.007  0.098        
## grp1:RT_z:1 -0.006  0.122  0.043  0.007 -0.020 -0.222 -0.097  -0.031
fit = lmer(scale(DAN_sig_z) ~ group * (RT_z * reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (-1 + RT_z:reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC_allfmri %>%
              filter(!subid %in% c('ap110', 'ap158', 'ap173')))
coef(fit)
## $subid
##              reps2         reps4    RT_z:reps2    RT_z:reps4  (Intercept)
## ap100  0.012293203 -0.0084694959 -0.0141922757 -0.0178259953 -0.007147128
## ap101  0.013669566 -0.0094177518  0.0273263231  0.0343228189 -0.007147128
## ap102  0.017114075 -0.0117908727  0.0020775534  0.0026094799 -0.007147128
## ap103 -0.011752974  0.0080973012 -0.0308194870 -0.0387103551 -0.007147128
## ap104 -0.013353940  0.0092002990 -0.0342700021 -0.0430443229 -0.007147128
## ap105 -0.004912647  0.0033846058 -0.0090027216 -0.0113077336 -0.007147128
## ap107 -0.023615667  0.0162701941  0.0288655113  0.0362560931 -0.007147128
## ap108 -0.010238193  0.0070536815 -0.0055017252 -0.0069103596 -0.007147128
## ap109 -0.012994024  0.0089523319  0.0027962545  0.0035121936 -0.007147128
## ap111 -0.011917392  0.0082105781 -0.0059001742 -0.0074108254 -0.007147128
## ap113  0.017604544 -0.0121287853  0.0149049887  0.0187211878 -0.007147128
## ap114 -0.012236719  0.0084305811 -0.0280142585 -0.0351868898 -0.007147128
## ap115 -0.009954533  0.0068582512  0.0076838707  0.0096512108 -0.007147128
## ap116  0.087819839 -0.0605041483  0.0199322777  0.0250356388 -0.007147128
## ap117  0.001717520 -0.0011832987 -0.0224964494 -0.0282563283 -0.007147128
## ap118  0.009063445 -0.0062443293  0.0168404922  0.0211522480 -0.007147128
## ap119 -0.001962590  0.0013521415  0.0065642167  0.0082448860 -0.007147128
## ap120 -0.017973065  0.0123826806 -0.0109327155 -0.0137318736 -0.007147128
## ap121  0.015331191 -0.0105625410 -0.0101038260 -0.0126907593 -0.007147128
## ap122 -0.043701638  0.0301085768  0.0442421468  0.0555696859 -0.007147128
## ap150  0.068587094 -0.0472536018 -0.0138917608 -0.0174485381 -0.007147128
## ap152  0.001112299 -0.0007663267  0.0169125743  0.0212427857 -0.007147128
## ap153  0.030104825 -0.0207409489  0.0211628178  0.0265812403 -0.007147128
## ap154 -0.023721066  0.0163428091 -0.0400612848 -0.0503183768 -0.007147128
## ap155  0.018397186 -0.0126748817 -0.0274613371 -0.0344924012 -0.007147128
## ap157 -0.055369807  0.0381474510 -0.0192384141 -0.0241641219 -0.007147128
## ap159 -0.024524567  0.0168963876  0.0061759971  0.0077572686 -0.007147128
## ap160  0.012021921 -0.0082825943 -0.0193255061 -0.0242735126 -0.007147128
## ap161  0.041503869 -0.0285944075  0.0011097597  0.0013938971 -0.007147128
## ap162  0.005994880 -0.0041302183  0.0199318958  0.0250351592 -0.007147128
## ap163  0.028278696 -0.0194828235 -0.0088529183 -0.0111195755 -0.007147128
## ap164 -0.019409900  0.0133725988 -0.0082015673 -0.0103014557 -0.007147128
## ap165  0.028878169 -0.0198958350  0.0004773888  0.0005996171 -0.007147128
## ap166 -0.029401809  0.0202566007  0.0440300579  0.0553032948 -0.007147128
## ap167 -0.033492042  0.0230745977 -0.0045153363 -0.0056714205 -0.007147128
## ap168  0.011764264 -0.0081050795 -0.0062635896 -0.0078672880 -0.007147128
## ap169 -0.067559771  0.0465458197  0.0112136112  0.0140846883 -0.007147128
## ap170  0.025956125 -0.0178826702  0.0107612467  0.0135165028 -0.007147128
## ap171 -0.008775318  0.0060458226  0.0154469664  0.0194019307 -0.007147128
## ap172 -0.015381118  0.0105969389 -0.0132021369 -0.0165823463 -0.007147128
## ap174  0.005036070 -0.0034696387  0.0137915358  0.0173226520 -0.007147128
##             group1       RT_z      reps1   shockCond1  RT_z:reps1
## ap100 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap101 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap102 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap103 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap104 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap105 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap107 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap108 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap109 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap111 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap113 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap114 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap115 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap116 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap117 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap118 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap119 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap120 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap121 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap122 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap150 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap152 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap153 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap154 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap155 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap157 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap159 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap160 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap161 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap162 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap163 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap164 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap165 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap166 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap167 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap168 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap169 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap170 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap171 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap172 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
## ap174 -0.002905196 0.08661835 0.03905343 -0.005661439 0.002784899
##       group1:RT_z group1:reps1 group1:RT_z:reps1
## ap100   0.0412895   0.01795923      -0.003807805
## ap101   0.0412895   0.01795923      -0.003807805
## ap102   0.0412895   0.01795923      -0.003807805
## ap103   0.0412895   0.01795923      -0.003807805
## ap104   0.0412895   0.01795923      -0.003807805
## ap105   0.0412895   0.01795923      -0.003807805
## ap107   0.0412895   0.01795923      -0.003807805
## ap108   0.0412895   0.01795923      -0.003807805
## ap109   0.0412895   0.01795923      -0.003807805
## ap111   0.0412895   0.01795923      -0.003807805
## ap113   0.0412895   0.01795923      -0.003807805
## ap114   0.0412895   0.01795923      -0.003807805
## ap115   0.0412895   0.01795923      -0.003807805
## ap116   0.0412895   0.01795923      -0.003807805
## ap117   0.0412895   0.01795923      -0.003807805
## ap118   0.0412895   0.01795923      -0.003807805
## ap119   0.0412895   0.01795923      -0.003807805
## ap120   0.0412895   0.01795923      -0.003807805
## ap121   0.0412895   0.01795923      -0.003807805
## ap122   0.0412895   0.01795923      -0.003807805
## ap150   0.0412895   0.01795923      -0.003807805
## ap152   0.0412895   0.01795923      -0.003807805
## ap153   0.0412895   0.01795923      -0.003807805
## ap154   0.0412895   0.01795923      -0.003807805
## ap155   0.0412895   0.01795923      -0.003807805
## ap157   0.0412895   0.01795923      -0.003807805
## ap159   0.0412895   0.01795923      -0.003807805
## ap160   0.0412895   0.01795923      -0.003807805
## ap161   0.0412895   0.01795923      -0.003807805
## ap162   0.0412895   0.01795923      -0.003807805
## ap163   0.0412895   0.01795923      -0.003807805
## ap164   0.0412895   0.01795923      -0.003807805
## ap165   0.0412895   0.01795923      -0.003807805
## ap166   0.0412895   0.01795923      -0.003807805
## ap167   0.0412895   0.01795923      -0.003807805
## ap168   0.0412895   0.01795923      -0.003807805
## ap169   0.0412895   0.01795923      -0.003807805
## ap170   0.0412895   0.01795923      -0.003807805
## ap171   0.0412895   0.01795923      -0.003807805
## ap172   0.0412895   0.01795923      -0.003807805
## ap174   0.0412895   0.01795923      -0.003807805
## 
## attr(,"class")
## [1] "coef.mer"
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_sig_z) ~ group * (RT_z * reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (-1 + RT_z:reps | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized_HC_allfmri %>% filter(!subid %in% c("ap110",  
##     "ap158", "ap173"))
## 
## REML criterion at convergence: 8213.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9938 -0.6076  0.0069  0.6602  3.6105 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.004831 0.06950       
##           reps4       0.002293 0.04788  -1.00
##  subid.1  RT_z        0.000000 0.00000       
##  subid.2  RT_z:reps2  0.002352 0.04850       
##           RT_z:reps4  0.003711 0.06092  1.00 
##  subid.3  (Intercept) 0.000000 0.00000       
##  Residual             0.984821 0.99238       
## Number of obs: 2888, groups:  subid, 41
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       -7.147e-03  1.959e-02  1.100e+03  -0.365 0.715301    
## group1            -2.905e-03  1.959e-02  1.100e+03  -0.148 0.882124    
## RT_z               8.662e-02  2.131e-02  4.110e+01   4.065 0.000212 ***
## reps1              3.905e-02  2.180e-02  3.880e+01   1.792 0.080979 .  
## shockCond1        -5.661e-03  1.852e-02  2.870e+03  -0.306 0.759812    
## RT_z:reps1         2.785e-03  1.935e-02  1.789e+03   0.144 0.885566    
## group1:RT_z        4.129e-02  2.131e-02  4.110e+01   1.938 0.059552 .  
## group1:reps1       1.796e-02  2.180e-02  3.880e+01   0.824 0.415029    
## group1:RT_z:reps1 -3.808e-03  1.935e-02  1.790e+03  -0.197 0.844023    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 RT_z:1 gr1:RT_ grp1:1
## group1      -0.223                                                  
## RT_z        -0.034  0.007                                           
## reps1       -0.220  0.058  0.099                                    
## shockCond1  -0.015  0.008 -0.011 -0.011                             
## RT_z:reps1   0.122 -0.007 -0.097 -0.031  0.011                      
## group1:RT_z  0.007 -0.034 -0.182 -0.009  0.014  0.043               
## group1:rps1  0.058 -0.221 -0.008 -0.178 -0.014  0.007  0.098        
## grp1:RT_z:1 -0.006  0.122  0.043  0.007 -0.020 -0.222 -0.097  -0.031
dCleanStandardized_HC_allfmri %>% filter(!subid %in% c('ap110', 'ap158', 'ap173')) %>%
  group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    20
## 2  stress    21

2b (ii): Excluding 2 subjs w/poor vtc localizer (trial-wise criteria from above)

Is VTC reinstatement modulated?

summary(lmer(ERActUnsigned ~ group * (RT_z * reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (RT_z * reps) + shockCond + (-1 + reps |  
##     subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7940
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4449 -0.6519 -0.0346  0.6553  3.4585 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.005098 0.07140       
##           reps4       0.002325 0.04822  -1.00
##  subid.1  RT_z        0.020564 0.14340       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.970349 0.98506       
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept)       -5.062e-03  2.019e-02  1.005e+03  -0.251   0.8021  
## group1             2.853e-03  2.019e-02  1.004e+03   0.141   0.8876  
## RT_z               5.266e-02  3.068e-02  3.640e+01   1.716   0.0946 .
## reps1              3.912e-02  2.253e-02  4.630e+01   1.736   0.0892 .
## shockCond1         6.336e-03  1.874e-02  2.768e+03   0.338   0.7353  
## RT_z:reps1         3.021e-02  2.009e-02  2.739e+03   1.503   0.1329  
## group1:RT_z        6.120e-02  3.068e-02  3.640e+01   1.995   0.0536 .
## group1:reps1      -1.024e-02  2.254e-02  4.630e+01  -0.454   0.6516  
## group1:RT_z:reps1 -1.092e-02  2.010e-02  2.739e+03  -0.543   0.5869  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 RT_z:1 gr1:RT_ grp1:1
## group1      -0.287                                                  
## RT_z        -0.030  0.011                                           
## reps1       -0.233  0.074  0.079                                    
## shockCond1  -0.024  0.022 -0.012 -0.007                             
## RT_z:reps1   0.135 -0.032 -0.099 -0.031  0.011                      
## group1:RT_z  0.011 -0.030 -0.152 -0.026  0.012  0.035               
## group1:rps1  0.074 -0.233 -0.026 -0.242 -0.023  0.014  0.079        
## grp1:RT_z:1 -0.031  0.135  0.035  0.014 -0.020 -0.285 -0.099  -0.031

Modulation of HC recollection decisions by RT

LH CCN

mean(dCleanStandardized_HC$RT_z)
## [1] -1.873681e-17
sd(dCleanStandardized_HC$RT_z)
## [1] 1
mean(dCleanStandardized_HC %>% filter(subid =='ap150') %>% pull(RT_z))
## [1] 1.263835e-16
sd(dCleanStandardized_HC %>% filter(subid =='ap150') %>% pull(RT_z))
## [1] 1.007414
dCleanStandardized_HC %>% group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    20
# first lh only
fit  = lmer(scale(CCN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC)
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_lh_sig_z) ~ group * (RT_z + reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7910.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8505 -0.6201  0.0141  0.6403  3.7477 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       1.229e-16 1.109e-08  NaN
##  subid.1  RT_z        3.309e-03 5.753e-02     
##  subid.2  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.751e-01 9.875e-01     
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -4.564e-03  1.990e-02  2.755e+03  -0.229   0.8186    
## group1       -6.656e-03  1.990e-02  2.756e+03  -0.334   0.7381    
## RT_z          1.230e-01  2.191e-02  3.560e+01   5.613 2.38e-06 ***
## reps1         2.531e-02  2.010e-02  2.788e+03   1.259   0.2081    
## shockCond1    1.368e-02  1.871e-02  2.789e+03   0.731   0.4650    
## group1:RT_z   5.828e-02  2.191e-02  3.560e+01   2.661   0.0116 *  
## group1:reps1  3.806e-02  2.010e-02  2.788e+03   1.893   0.0584 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 g1:RT_
## group1      -0.292                                   
## RT_z        -0.023  0.008                            
## reps1       -0.204  0.078  0.117                     
## shockCond1  -0.026  0.024 -0.014 -0.008              
## group1:RT_z  0.008 -0.023 -0.241 -0.029  0.013       
## group1:rps1  0.079 -0.205 -0.029 -0.288 -0.021  0.116
# make sure holds when removing rep effect
# summary(lmer(scale(CCN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + RT_z|subid)+
#               (1 |subid), 
#             data=dCleanStandardized_HC))

# explore interaction of group * rt
summary(lmer(scale(CCN_lh_sig_z) ~ RT_z + reps  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC%>% filter(group == 'control')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_lh_sig_z) ~ RT_z + reps + shockCond + (-1 + reps |  
##     subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(group == "control")
## 
## REML criterion at convergence: 5052.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8479 -0.6044  0.0358  0.6425  3.7712 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       3.092e-17 5.561e-09  NaN
##  subid.1  RT_z        2.649e-03 5.146e-02     
##  subid.2  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.649e-01 9.823e-01     
## Number of obs: 1795, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept) -1.116e-02  2.356e-02  1.772e+03  -0.474  0.63579    
## RT_z         1.813e-01  2.624e-02  1.630e+01   6.909 3.16e-06 ***
## reps1        6.339e-02  2.386e-02  1.782e+03   2.657  0.00795 ** 
## shockCond1   4.924e-03  2.322e-02  1.789e+03   0.212  0.83207    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.022              
## reps1      -0.177  0.123       
## shockCond1 -0.002 -0.001 -0.030
summary(lmer(scale(CCN_lh_sig_z) ~ RT_z + reps + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC%>% filter(group == 'stress'),
            control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_lh_sig_z) ~ RT_z + reps + shockCond + (-1 + reps |  
##     subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(group == "stress")
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 2856.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.7611 -0.6446 -0.0120  0.6406  3.1833 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.008127 0.09015       
##           reps4       0.003236 0.05689  -1.00
##  subid.1  RT_z        0.004847 0.06962       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.988153 0.99406       
## Number of obs: 1002, groups:  subid, 20
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept)  9.933e-04  3.259e-02  2.811e+02   0.030   0.9757  
## RT_z         6.398e-02  3.604e-02  1.530e+01   1.775   0.0957 .
## reps1       -1.233e-02  3.712e-02  1.560e+01  -0.332   0.7442  
## shockCond1   2.962e-02  3.160e-02  9.962e+02   0.937   0.3488  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.023              
## reps1      -0.256  0.100       
## shockCond1 -0.053 -0.029  0.018
# check to make sure simple effects are same
# contrasts(dCleanStandardized_HC$group) = c(0,1)
# summary(lmer(scale(CCN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + reps|subid)+
#               (-1 + RT_z|subid)+
#               (1 |subid), 
#             data=dCleanStandardized_HC))
# 
# contrasts(dCleanStandardized_HC$group) = c(1,0)
# summary(lmer(scale(CCN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + reps|subid)+
#               (-1 + RT_z|subid)+
#               (1 |subid), 
#             data=dCleanStandardized_HC))
# contrasts(dCleanStandardized_HC$group) = c(1,-1)

# interaction between shockcond and RT on CCN? in stress group
# remove subjs w/trial counts/bin < 6
dCleanStandardized_HC %>% filter(group == 'stress') %>% 
  group_by(subid, shockCond) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, shockCond, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 1 x 3
##    subid shockCond count
##   <fctr>    <fctr> <dbl>
## 1  ap173    threat     1
summary(lmer(scale(CCN_lh_sig_z) ~ (RT_z + reps) + shockCond +
               shockCond:RT_z +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
               (-1 + shockCond|subid)+
               (-1 + shockCond:RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC %>% filter(group == 'stress',
                                                  subid != 'ap173')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(CCN_lh_sig_z) ~ (RT_z + reps) + shockCond + shockCond:RT_z +  
##     (-1 + reps | subid) + (-1 + RT_z | subid) + (-1 + shockCond |  
##     subid) + (-1 + shockCond:RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(group == "stress", subid !=  
##     "ap173")
## 
## REML criterion at convergence: 2832
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8162 -0.6450 -0.0056  0.6411  3.2381 
## 
## Random effects:
##  Groups   Name                 Variance  Std.Dev.  Corr 
##  subid    reps2                4.022e-03 6.342e-02      
##           reps4                1.634e-03 4.043e-02 -1.00
##  subid.1  RT_z                 0.000e+00 0.000e+00      
##  subid.2  shockCondsafe        0.000e+00 0.000e+00      
##           shockCondthreat      7.915e-15 8.896e-08  NaN 
##  subid.3  shockCondsafe:RT_z   3.323e-02 1.823e-01      
##           shockCondthreat:RT_z 1.429e-03 3.780e-02 -1.00
##  subid.4  (Intercept)          0.000e+00 0.000e+00      
##  Residual                      9.772e-01 9.885e-01      
## Number of obs: 994, groups:  subid, 19
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept)       0.002146   0.032479 408.100000   0.066   0.9474  
## RT_z              0.069173   0.036358  32.300000   1.903   0.0661 .
## reps1            -0.015523   0.035029  14.200000  -0.443   0.6643  
## shockCond1        0.031493   0.031482 973.900000   1.000   0.3174  
## RT_z:shockCond1   0.029239   0.041072  20.600000   0.712   0.4845  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) RT_z   reps1  shckC1
## RT_z        -0.018                     
## reps1       -0.236  0.098              
## shockCond1  -0.042 -0.023  0.018       
## RT_z:shckC1 -0.026  0.289  0.024  0.004
dCleanStandardized_HC %>% filter(group == 'stress',
                                 subid != 'ap173') %>%
  group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 1 x 2
##    group `n()`
##   <fctr> <int>
## 1 stress    19
# is the RT * rep interaction significant?
dCleanStandardized_HC %>% 
  group_by(subid, reps) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, reps, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 3 x 3
##    subid   reps count
##   <fctr> <fctr> <dbl>
## 1  ap110      2     3
## 2  ap158      2     2
## 3  ap173      2     2
summary(lmer(scale(CCN_lh_sig_z) ~ group * (RT_z * reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
               (-1 + RT_z:reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC %>%
              filter(!subid %in% c('ap110', 'ap158', 'ap173'))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_lh_sig_z) ~ group * (RT_z * reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (-1 + RT_z:reps | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(!subid %in% c("ap110", "ap158",  
##     "ap173"))
## 
## REML criterion at convergence: 7815.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8424 -0.6222  0.0134  0.6445  3.7462 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  subid    reps2       8.169e-15 9.038e-08      
##           reps4       1.166e-14 1.080e-07 -1.00
##  subid.1  RT_z        3.916e-10 1.979e-05      
##  subid.2  RT_z:reps2  3.552e-03 5.960e-02      
##           RT_z:reps4  3.068e-03 5.539e-02 1.00 
##  subid.3  (Intercept) 0.000e+00 0.000e+00      
##  Residual             9.769e-01 9.884e-01      
## Number of obs: 2758, groups:  subid, 39
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       -4.246e-03  2.020e-02  2.716e+03  -0.210   0.8336    
## group1            -8.325e-03  2.020e-02  2.716e+03  -0.412   0.6803    
## RT_z               1.214e-01  2.221e-02  3.370e+01   5.468 4.37e-06 ***
## reps1              2.332e-02  2.023e-02  2.746e+03   1.153   0.2491    
## shockCond1         1.360e-02  1.886e-02  2.748e+03   0.721   0.4709    
## RT_z:reps1        -8.333e-04  2.003e-02  1.764e+03  -0.042   0.9668    
## group1:RT_z        5.564e-02  2.221e-02  3.370e+01   2.505   0.0173 *  
## group1:reps1       3.727e-02  2.023e-02  2.746e+03   1.842   0.0656 .  
## group1:RT_z:reps1 -1.490e-02  2.004e-02  1.762e+03  -0.744   0.4571    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 RT_z:1 gr1:RT_ grp1:1
## group1      -0.286                                                  
## RT_z        -0.038  0.012                                           
## reps1       -0.203  0.080  0.121                                    
## shockCond1  -0.024  0.017 -0.012 -0.006                             
## RT_z:reps1   0.135 -0.028 -0.120 -0.038  0.009                      
## group1:RT_z  0.012 -0.038 -0.237 -0.028  0.015  0.041               
## group1:rps1  0.081 -0.203 -0.027 -0.284 -0.019  0.013  0.121        
## grp1:RT_z:1 -0.028  0.135  0.041  0.014 -0.018 -0.281 -0.120  -0.038
dCleanStandardized_HC %>% filter(!subid %in% c('ap110', 'ap158', 'ap173')) %>%
  group_by(subid, group) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    20
## 2  stress    19
Slopes for each subj
datalist = list()
i = 1
for (subject in unique(dCleanStandardized_HC$subid)){
  print(subject)
  fit  = lm(CCN_lh_sig_z ~ RT_z + reps + shockCond,
            data=dCleanStandardized_HC %>% filter(subid == subject))
  print(fit$coefficients['RT_z'])
  dat = data.frame(subid=subject,
                   coef = fit$coefficients['RT_z'])
  datalist[[i]] <- dat 
  i = 1+i
}
## [1] "ap100"
##      RT_z 
## 0.1845116 
## [1] "ap101"
##      RT_z 
## 0.2047765 
## [1] "ap102"
##      RT_z 
## 0.1459256 
## [1] "ap103"
##      RT_z 
## 0.1639334 
## [1] "ap104"
##      RT_z 
## 0.1751052 
## [1] "ap105"
##      RT_z 
## 0.3370491 
## [1] "ap107"
##      RT_z 
## 0.3571874 
## [1] "ap108"
##      RT_z 
## 0.1790157 
## [1] "ap109"
##       RT_z 
## 0.06314569 
## [1] "ap110"
##      RT_z 
## 0.3037418 
## [1] "ap111"
##      RT_z 
## 0.1025788 
## [1] "ap113"
##      RT_z 
## 0.2607868 
## [1] "ap114"
##      RT_z 
## 0.1346667 
## [1] "ap115"
##       RT_z 
## -0.2408414 
## [1] "ap116"
##      RT_z 
## 0.1734513 
## [1] "ap117"
##     RT_z 
## 0.185716 
## [1] "ap118"
##      RT_z 
## 0.1506152 
## [1] "ap119"
##      RT_z 
## 0.2439138 
## [1] "ap120"
##      RT_z 
## 0.1436209 
## [1] "ap121"
##       RT_z 
## 0.02858525 
## [1] "ap122"
##      RT_z 
## 0.1926783 
## [1] "ap158"
##      RT_z 
## 0.6110446 
## [1] "ap150"
##         RT_z 
## -0.004798299 
## [1] "ap152"
##      RT_z 
## 0.2222908 
## [1] "ap153"
##       RT_z 
## 0.02737265 
## [1] "ap154"
##       RT_z 
## -0.2121761 
## [1] "ap155"
##       RT_z 
## -0.1092804 
## [1] "ap157"
##       RT_z 
## 0.02666674 
## [1] "ap159"
##      RT_z 
## 0.1598098 
## [1] "ap160"
##       RT_z 
## -0.2262615 
## [1] "ap161"
##        RT_z 
## 0.008245208 
## [1] "ap162"
##      RT_z 
## 0.1630138 
## [1] "ap163"
##       RT_z 
## 0.01060648 
## [1] "ap164"
##     RT_z 
## 0.205875 
## [1] "ap165"
##       RT_z 
## 0.07193465 
## [1] "ap166"
##      RT_z 
## 0.3259992 
## [1] "ap167"
##        RT_z 
## -0.03177933 
## [1] "ap169"
##       RT_z 
## 0.04059666 
## [1] "ap170"
##       RT_z 
## 0.09091969 
## [1] "ap171"
##      RT_z 
## 0.3231811 
## [1] "ap172"
##      RT_z 
## 0.1333716 
## [1] "ap173"
##       RT_z 
## -0.1138961
slopes_ccn_rt <- dplyr::bind_rows(datalist)
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
slopes_ccn_rt
##    subid         coef
## 1  ap100  0.184511557
## 2  ap101  0.204776511
## 3  ap102  0.145925568
## 4  ap103  0.163933423
## 5  ap104  0.175105217
## 6  ap105  0.337049069
## 7  ap107  0.357187417
## 8  ap108  0.179015663
## 9  ap109  0.063145689
## 10 ap110  0.303741792
## 11 ap111  0.102578839
## 12 ap113  0.260786820
## 13 ap114  0.134666679
## 14 ap115 -0.240841380
## 15 ap116  0.173451254
## 16 ap117  0.185715962
## 17 ap118  0.150615230
## 18 ap119  0.243913788
## 19 ap120  0.143620858
## 20 ap121  0.028585255
## 21 ap122  0.192678267
## 22 ap158  0.611044591
## 23 ap150 -0.004798299
## 24 ap152  0.222290779
## 25 ap153  0.027372646
## 26 ap154 -0.212176088
## 27 ap155 -0.109280428
## 28 ap157  0.026666741
## 29 ap159  0.159809764
## 30 ap160 -0.226261477
## 31 ap161  0.008245208
## 32 ap162  0.163013822
## 33 ap163  0.010606480
## 34 ap164  0.205875041
## 35 ap165  0.071934655
## 36 ap166  0.325999195
## 37 ap167 -0.031779329
## 38 ap169  0.040596662
## 39 ap170  0.090919687
## 40 ap171  0.323181115
## 41 ap172  0.133371621
## 42 ap173 -0.113896059

LH DAN

### DAN
summary(lmer(scale(DAN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_lh_sig_z) ~ group * (RT_z + reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7916.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1961 -0.6013 -0.0067  0.6499  3.8548 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.003463 0.05884       
##           reps4       0.001566 0.03957  -1.00
##  subid.1  RT_z        0.002964 0.05444       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.975570 0.98771       
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -7.010e-03  2.001e-02  1.158e+03  -0.350   0.7262    
## group1       -2.715e-03  2.001e-02  1.156e+03  -0.136   0.8921    
## RT_z          1.190e-01  2.172e-02  4.010e+01   5.481 2.51e-06 ***
## reps1         3.612e-02  2.176e-02  3.890e+01   1.660   0.1049    
## shockCond1   -5.597e-03  1.873e-02  2.782e+03  -0.299   0.7651    
## group1:RT_z   5.700e-02  2.172e-02  4.010e+01   2.625   0.0122 *  
## group1:reps1  1.726e-02  2.176e-02  3.890e+01   0.793   0.4326    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 g1:RT_
## group1      -0.290                                   
## RT_z        -0.023  0.008                            
## reps1       -0.223  0.074  0.109                     
## shockCond1  -0.026  0.025 -0.014 -0.007              
## group1:RT_z  0.008 -0.023 -0.244 -0.029  0.014       
## group1:rps1  0.075 -0.223 -0.028 -0.254 -0.022  0.109
# explore interaction of group * rt
summary(lmer(scale(DAN_lh_sig_z) ~ RT_z + reps  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC%>% filter(group == 'control')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_lh_sig_z) ~ RT_z + reps + shockCond + (-1 + reps |  
##     subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(group == "control")
## 
## REML criterion at convergence: 5058.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8479 -0.5884  0.0218  0.6535  3.8557 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       3.864e-15 6.216e-08  NaN
##  subid.1  RT_z        1.630e-03 4.037e-02     
##  subid.2  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.687e-01 9.842e-01     
## Number of obs: 1795, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept) -9.165e-03  2.361e-02  1.778e+03  -0.388   0.6979    
## RT_z         1.766e-01  2.524e-02  2.270e+01   6.995 4.28e-07 ***
## reps1        5.189e-02  2.388e-02  1.782e+03   2.173   0.0299 *  
## shockCond1   8.016e-03  2.326e-02  1.790e+03   0.345   0.7304    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.023              
## reps1      -0.177  0.129       
## shockCond1 -0.002 -0.001 -0.030
summary(lmer(scale(DAN_lh_sig_z) ~ RT_z + reps + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC%>% filter(group == 'stress'),
            control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_lh_sig_z) ~ RT_z + reps + shockCond + (-1 + reps |  
##     subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(group == "stress")
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 2853.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1480 -0.6158 -0.0349  0.6468  3.2952 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.025136 0.15854       
##           reps4       0.009454 0.09723  -1.00
##  subid.1  RT_z        0.009058 0.09517       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.976237 0.98805       
## Number of obs: 1002, groups:  subid, 20
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)  -0.004434   0.033099 122.800000  -0.134    0.894
## RT_z          0.065168   0.039129  15.000000   1.665    0.117
## reps1         0.018851   0.044510  15.900000   0.424    0.678
## shockCond1   -0.029215   0.031515 993.600000  -0.927    0.354
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.023              
## reps1      -0.317  0.082       
## shockCond1 -0.054 -0.027  0.019
# double check simple effects
# contrasts(dCleanStandardized_HC$group) = c(0,1)
# summary(lmer(scale(DAN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + reps|subid)+
#               (-1 + RT_z|subid)+
#               (1 |subid), 
#             data=dCleanStandardized_HC))
# contrasts(dCleanStandardized_HC$group) = c(1,0)
# summary(lmer(scale(DAN_lh_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + reps|subid)+
#               (-1 + RT_z|subid)+
#               (1 |subid), 
#             data=dCleanStandardized_HC))
# contrasts(dCleanStandardized_HC$group) = c(1,-1)


# interaction between shockcond and RT on DAN? in stress group
# remove subjs w/trial counts/bin < 6
dCleanStandardized_HC %>% filter(group == 'stress') %>% 
  group_by(subid, shockCond) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, shockCond, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 1 x 3
##    subid shockCond count
##   <fctr>    <fctr> <dbl>
## 1  ap173    threat     1
# remove slopes to converge
summary(lmer(scale(DAN_lh_sig_z) ~ (RT_z + reps) + shockCond +
               shockCond:RT_z +
              (-1 + RT_z|subid)+
               (-1 + shockCond|subid)+
              (1 |subid), 
              control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5)),
            data=dCleanStandardized_HC %>% filter(group == 'stress',
                                                  subid != 'ap173')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(DAN_lh_sig_z) ~ (RT_z + reps) + shockCond + shockCond:RT_z +  
##     (-1 + RT_z | subid) + (-1 + shockCond | subid) + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(group == "stress", subid !=  
##     "ap173")
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 2839.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.2286 -0.5898 -0.0320  0.6266  3.2936 
## 
## Random effects:
##  Groups   Name            Variance  Std.Dev.  Corr
##  subid    RT_z            7.996e-03 8.942e-02     
##  subid.1  shockCondsafe   0.000e+00 0.000e+00     
##           shockCondthreat 1.242e-12 1.114e-06  NaN
##  subid.2  (Intercept)     0.000e+00 0.000e+00     
##  Residual                 9.923e-01 9.962e-01     
## Number of obs: 994, groups:  subid, 19
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)      -0.002628   0.032427 971.700000  -0.081    0.935
## RT_z              0.057636   0.038627  14.800000   1.492    0.157
## reps1             0.018513   0.032721 988.500000   0.566    0.572
## shockCond1       -0.027980   0.031762 989.000000  -0.881    0.379
## RT_z:shockCond1  -0.003997   0.032159 854.300000  -0.124    0.901
## 
## Correlation of Fixed Effects:
##             (Intr) RT_z   reps1  shckC1
## RT_z        -0.020                     
## reps1       -0.219  0.103              
## shockCond1  -0.047 -0.024  0.016       
## RT_z:shckC1 -0.035 -0.033  0.025  0.006
# is the RT * rep interaction significant?
dCleanStandardized_HC %>% 
  group_by(subid, reps) %>% 
  summarise(count=n()) %>% 
  ungroup() %>%
  mutate(subid = factor(subid)) %>%
  complete(subid, reps, fill = list(count= 0)) %>% filter(count < 6)
## # A tibble: 3 x 3
##    subid   reps count
##   <fctr> <fctr> <dbl>
## 1  ap110      2     3
## 2  ap158      2     2
## 3  ap173      2     2
summary(lmer(scale(DAN_lh_sig_z) ~ group * (RT_z * reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
               (-1 + RT_z:reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC %>%
              filter(!subid %in% c('ap110', 'ap158', 'ap173'))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_lh_sig_z) ~ group * (RT_z * reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (-1 + RT_z:reps | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(!subid %in% c("ap110", "ap158",  
##     "ap173"))
## 
## REML criterion at convergence: 7823.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.1900 -0.5953 -0.0078  0.6481  3.8411 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr 
##  subid    reps2       3.263e-03 5.712e-02      
##           reps4       1.522e-03 3.901e-02 -1.00
##  subid.1  RT_z        4.573e-10 2.138e-05      
##  subid.2  RT_z:reps2  2.334e-03 4.831e-02      
##           RT_z:reps4  3.249e-03 5.700e-02 1.00 
##  subid.3  (Intercept) 0.000e+00 0.000e+00      
##  Residual             9.781e-01 9.890e-01      
## Number of obs: 2758, groups:  subid, 39
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       -5.735e-03  2.030e-02  1.268e+03  -0.282   0.7776    
## group1            -2.537e-03  2.030e-02  1.267e+03  -0.125   0.9006    
## RT_z               1.127e-01  2.189e-02  4.130e+01   5.147 6.86e-06 ***
## reps1              3.540e-02  2.184e-02  3.880e+01   1.621   0.1131    
## shockCond1        -4.999e-03  1.888e-02  2.742e+03  -0.265   0.7912    
## RT_z:reps1         7.056e-03  2.003e-02  2.282e+03   0.352   0.7247    
## group1:RT_z        5.530e-02  2.189e-02  4.130e+01   2.526   0.0154 *  
## group1:reps1       1.606e-02  2.185e-02  3.880e+01   0.735   0.4666    
## group1:RT_z:reps1 -2.893e-03  2.003e-02  2.282e+03  -0.144   0.8852    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 RT_z:1 gr1:RT_ grp1:1
## group1      -0.284                                                  
## RT_z        -0.038  0.012                                           
## reps1       -0.218  0.076  0.114                                    
## shockCond1  -0.024  0.018 -0.013 -0.005                             
## RT_z:reps1   0.135 -0.028 -0.098 -0.036  0.009                      
## group1:RT_z  0.012 -0.038 -0.242 -0.027  0.015  0.040               
## group1:rps1  0.076 -0.219 -0.027 -0.251 -0.020  0.013  0.114        
## grp1:RT_z:1 -0.028  0.135  0.040  0.013 -0.018 -0.281 -0.098  -0.036

Plot combined lh networks

## collapse
dm_avg = dm %>% filter(pcorr == 1) %>%
  group_by(subid) %>%
  mutate(rt_quintile = ntile(respRT, 5)) %>%
  group_by(subid, group, rt_quintile) %>%
  summarise(ccn = mean_(CCN_lh_sig), 
            dan = mean_(DAN_lh_sig), 
            count = n()) %>% 
  gather(key = 'network', value = 'signal', ccn:dan) %>%
  mutate(network = replace(network, network=='ccn', 'CCN'),
         network = replace(network, network=='dan', 'DAN'))
  
dfwc = summarySEwithin(dm_avg, measurevar="signal", 
                       withinvars=c("rt_quintile", "network"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: rt_quintile, network
dfwc
##      group rt_quintile network  N     signal signal_norm         sd
## 1  control           1     CCN 22 0.03230130  0.04816599 0.06275263
## 2  control           1     DAN 22 0.01262089  0.02848558 0.07062237
## 3  control           2     CCN 22 0.07582863  0.09169332 0.07688394
## 4  control           2     DAN 22 0.04543842  0.06130311 0.06851596
## 5  control           3     CCN 22 0.14757958  0.16344426 0.09290254
## 6  control           3     DAN 22 0.10225941  0.11812409 0.08514998
## 7  control           4     CCN 22 0.14597583  0.16184051 0.10035884
## 8  control           4     DAN 22 0.10304145  0.11890614 0.08069073
## 9  control           5     CCN 22 0.19266350  0.20852819 0.07902218
## 10 control           5     DAN 22 0.15007843  0.16594312 0.06707180
## 11  stress           1     CCN 20 0.13589630  0.11844515 0.14677943
## 12  stress           1     DAN 20 0.09766938  0.08021822 0.11519604
## 13  stress           2     CCN 20 0.10776132  0.09031017 0.11690720
## 14  stress           2     DAN 20 0.07138553  0.05393438 0.09810813
## 15  stress           3     CCN 20 0.14729661  0.12984546 0.10832576
## 16  stress           3     DAN 20 0.12303627  0.10558512 0.12015161
## 17  stress           4     CCN 20 0.20514167  0.18769051 0.11972469
## 18  stress           4     DAN 20 0.14671511  0.12926396 0.12196308
## 19  stress           5     CCN 20 0.16806054  0.15060939 0.08556226
## 20  stress           5     DAN 20 0.13798308  0.12053193 0.11675133
##            se         ci
## 1  0.01337891 0.02782296
## 2  0.01505674 0.03131220
## 3  0.01639171 0.03408843
## 4  0.01460765 0.03037828
## 5  0.01980689 0.04119068
## 6  0.01815404 0.03775338
## 7  0.02139658 0.04449662
## 8  0.01720332 0.03577626
## 9  0.01684759 0.03503647
## 10 0.01429976 0.02973797
## 11 0.03282088 0.06869489
## 12 0.02575862 0.05391341
## 13 0.02614125 0.05471426
## 14 0.02193764 0.04591602
## 15 0.02422238 0.05069802
## 16 0.02686672 0.05623269
## 17 0.02677126 0.05603288
## 18 0.02727177 0.05708048
## 19 0.01913230 0.04004437
## 20 0.02610639 0.05464130
p2 = ggplot(dfwc, aes(x=rt_quintile, y=signal, group=group, color=group)) +
  facet_grid(.~network)+
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=signal-se, 
                               ymax=signal+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('Percent signal change')+
  xlab('RT (quintiles)')+
  ylim(-.015, .235)+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))


ggsave(p2,
       filename ='~/Experiments/AP/figs/respRTXfrontoparietalLH_quintile_HCrecollection.jpg',
       dpi=150, width = 9, height=4)

ggsave(p2,
       filename ='~/Dropbox/Stanford/Papers/Dissertation/Figures_defense/AP_respRTXfrontoparietalLH_quintile_HCrecollection.jpg',
       dpi=300, width = 9, height=4)


p1 = ggplot(dfwc %>% filter(group == 'control'), aes(x=rt_quintile, y=signal, group=group, color=group)) +
  facet_grid(.~network)+
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=signal-se, 
                               ymax=signal+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('Percent signal change')+
  xlab('RT (quintiles)')+
  ylim(-.015, .235)+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p1

ggsave(p1,
       filename ='~/Dropbox/Stanford/Papers/Dissertation/Figures_defense/AP_respRTXfrontoparietalLH_quintile_HCrecollection_controlonly.jpg',
       dpi=300, width = 9, height=4)

p2

## plot stress by shockCond
dm_avg = dm %>% filter(pcorr == 1,
                       group == 'stress',
                       subid != 'ap173') %>%
  group_by(subid) %>%
  mutate(rt_quintile = ntile(respRT, 5)) %>%
  group_by(subid, shockCond, rt_quintile) %>%
  summarise(ccn = mean_(CCN_lh_sig), 
            dan = mean_(DAN_lh_sig), 
            count = n()) %>% 
  gather(key = 'network', value = 'signal', ccn:dan) %>%
  mutate(network = replace(network, network=='ccn', 'CCN'),
         network = replace(network, network=='dan', 'DAN'))
dm_avg
## Source: local data frame [378 x 6]
## Groups: subid, shockCond [38]
## 
## # A tibble: 378 x 6
##     subid shockCond rt_quintile count network      signal
##    <fctr>    <fctr>       <int> <int>   <chr>       <dbl>
##  1  ap150      safe           1     6     CCN  0.12465318
##  2  ap150      safe           2     6     CCN -0.04759280
##  3  ap150      safe           3     7     CCN  0.11967741
##  4  ap150      safe           4     8     CCN  0.34404922
##  5  ap150      safe           5     6     CCN  0.47773393
##  6  ap150    threat           1     8     CCN  0.36193132
##  7  ap150    threat           2     7     CCN  0.16074072
##  8  ap150    threat           3     6     CCN -0.10565980
##  9  ap150    threat           4     5     CCN  0.07337990
## 10  ap150    threat           5     7     CCN -0.01907539
## # ... with 368 more rows
dfwc = summarySEwithin(dm_avg, measurevar="signal", 
                       withinvars=c("rt_quintile", "network", "shockCond"),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: rt_quintile, network
dfwc
##    rt_quintile network shockCond  N     signal signal_norm        sd
## 1            1     CCN      safe 19 0.10636532  0.10629496 0.1950704
## 2            1     CCN    threat 19 0.11400598  0.11393562 0.1486527
## 3            1     DAN      safe 19 0.06431018  0.06423982 0.1259749
## 4            1     DAN    threat 19 0.14225934  0.14218898 0.1735881
## 5            2     CCN      safe 19 0.16436471  0.16429435 0.1815611
## 6            2     CCN    threat 19 0.07176070  0.07169034 0.1546956
## 7            2     DAN      safe 19 0.14215485  0.14208449 0.1525689
## 8            2     DAN    threat 19 0.02219062  0.02212026 0.1474942
## 9            3     CCN      safe 19 0.15451356  0.15444319 0.1619787
## 10           3     CCN    threat 18 0.18592459  0.18659303 0.1588574
## 11           3     DAN      safe 19 0.11500784  0.11493748 0.2240081
## 12           3     DAN    threat 18 0.16257757  0.16324602 0.1833754
## 13           4     CCN      safe 19 0.22755111  0.22748075 0.1641223
## 14           4     CCN    threat 19 0.16997784  0.16990748 0.1826248
## 15           4     DAN      safe 19 0.13650646  0.13643609 0.1844395
## 16           4     DAN    threat 19 0.14512711  0.14505675 0.1921394
## 17           5     CCN      safe 19 0.19027665  0.19020629 0.1812135
## 18           5     CCN    threat 19 0.17079781  0.17072744 0.1618633
## 19           5     DAN      safe 19 0.13209532  0.13202496 0.2193852
## 20           5     DAN    threat 19 0.15853562  0.15846526 0.1634688
##            se         ci
## 1  0.04475221 0.09402091
## 2  0.03410327 0.07164832
## 3  0.02890063 0.06071798
## 4  0.03982384 0.08366678
## 5  0.04165298 0.08750966
## 6  0.03548961 0.07456091
## 7  0.03500170 0.07353585
## 8  0.03383749 0.07108993
## 9  0.03716046 0.07807122
## 10 0.03744305 0.07899792
## 11 0.05139098 0.10796845
## 12 0.04322201 0.09119046
## 13 0.03765223 0.07910439
## 14 0.04189700 0.08802233
## 15 0.04231331 0.08889697
## 16 0.04407980 0.09260823
## 17 0.04157322 0.08734209
## 18 0.03713399 0.07801561
## 19 0.05033042 0.10574030
## 20 0.03750231 0.07878944
p2 = ggplot(dfwc, aes(x=rt_quintile, y=signal, group=shockCond, color=shockCond)) +
  facet_grid(.~network)+
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=signal-se, 
                               ymax=signal+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('Percent signal change')+
  xlab('RT (quintiles)')+
  scale_color_manual(values=c('mediumpurple', 'darkorange'), 
                     guide = guide_legend(title = NULL)) 
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/stress_respRTXfrontoparietalLH_quintile_HCrecollection.jpg',
       dpi=150, width = 9, height=4)
p2

Look at lh CCN raw timecourse

Compare with misses first, just to make sure we’re getting good signal for HC assoc hits

ccn_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-frontoparietal.csv')

# first, compare with misses to make sure we're getting good signal for CCN:
# merge w/data (filter artifacts + get extra trial info)
ccn_lh = ccn_lh %>% filter(condition %in% c('sourcehit', 'M')) %>% 
  # inner join w/d, where have a new col indicating median of RT for that condition
  inner_join(d %>% group_by(subid, cond) %>% mutate(rt_bin = ntile(respRT, 3)) %>% ungroup(), 
             by=c('subid', 'run', 'onset')) %>%
  mutate(subid = factor(subid),
         cond = factor(cond))

with(ccn_lh, table(cond, condition.x))
##            condition.x
## cond           CR    FA itemhit_lo     M sourcehit sourcemiss_hi
##   M             0     0          0  7252         0             0
##   sourcehit     0     0          0     0     20489             0
ggplot(ccn_lh %>% group_by(subid, cond, time) %>% 
         summarise(ccn_sig = mean(mean_activity)) %>% 
         group_by(time, cond) %>% 
         summarise(mean(ccn_sig)), 
       aes(x=time, y=`mean(ccn_sig)`, color=cond, group=cond)) +
  geom_line()

Break down by RT
ccn_lh = ccn_lh %>% filter(cond == 'sourcehit')

# double check that split of RT is good
ccn_lh %>% filter(time == 0) %>% group_by(subid, group, rt_bin) %>% 
  summarise(mean(respRT), max(respRT), min(respRT))
## Source: local data frame [132 x 6]
## Groups: subid, group [?]
## 
## # A tibble: 132 x 6
##     subid   group rt_bin `mean(respRT)` `max(respRT)` `min(respRT)`
##    <fctr>  <fctr>  <int>          <dbl>         <dbl>         <dbl>
##  1  ap100 control      1       1.472169        1.8256        1.1028
##  2  ap100 control      2       2.091476        2.3408        1.8843
##  3  ap100 control      3       2.902400        3.9149        2.3666
##  4  ap101 control      1       1.524176        1.7988        1.1682
##  5  ap101 control      2       1.961079        2.1640        1.8012
##  6  ap101 control      3       2.655738        3.7207        2.2345
##  7  ap102 control      1       1.563682        1.7736        1.1019
##  8  ap102 control      2       1.993450        2.2263        1.7762
##  9  ap102 control      3       2.730459        3.7812        2.2745
## 10  ap103 control      1       2.292159        2.7029        1.6285
## # ... with 122 more rows
ccn_avg = ccn_lh %>% 
  group_by(subid, group, rt_bin, time) %>% 
  summarise(ccn_sig = mean(mean_activity)) %>%
  group_by(group, rt_bin, time) %>%
  summarise(mean = mean(ccn_sig), se = std.error(ccn_sig), n())
ccn_avg  
## Source: local data frame [42 x 6]
## Groups: group, rt_bin [?]
## 
## # A tibble: 42 x 6
##      group rt_bin  time         mean         se `n()`
##     <fctr>  <int> <int>        <dbl>      <dbl> <int>
##  1 control      1     0  0.037762404 0.02027021    22
##  2 control      1     2 -0.041527517 0.02286603    22
##  3 control      1     4  0.018019148 0.02060081    22
##  4 control      1     6  0.103588084 0.01943584    22
##  5 control      1     8  0.086801488 0.02100314    22
##  6 control      1    10 -0.031153485 0.02074640    22
##  7 control      1    12 -0.123887369 0.02401769    22
##  8 control      2     0 -0.008986119 0.02484918    22
##  9 control      2     2 -0.071288820 0.02342123    22
## 10 control      2     4  0.015258543 0.02030362    22
## # ... with 32 more rows
blues <- brewer.pal(4, "Blues")[2:4]
p2 = ggplot(ccn_avg, aes(x=factor(time), y=mean, group=factor(rt_bin), color=factor(rt_bin))) +
    facet_grid(.~group) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=mean-se, 
                               ymax=mean+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('CCN activity (% change)')+
  xlab('Time post-stimulus onset (s)') +
  guides(color=guide_legend(title="RT (tertile)")) +
  scale_color_manual(values=blues)
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/CCNlh_bytimeXrttertile_HCrecollection.jpg',
       dpi=150, width = 9, height=4)
p2

For comparison, take a look at posterior hippocampal ROI

Does this peak earlier, and CCN kicks in post-retrieval for evaluation? Or, is it extended (retrieving more memories)?

Compare with misses first, just to make sure we’re getting good signal for HC assoc hits

roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-hippocampus-tail.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-hippocampus-tail.csv')

# Collapse across hemispheres
ccn_lh = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcehit', 'M')) %>%
  group_by(subid, hemi, run, onset, time) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset, time) %>%
  summarise(mean_activity = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
ccn_lh
## # A tibble: 28,378 x 5
##     subid   run   onset  time mean_activity
##    <fctr> <int>   <dbl> <int>         <dbl>
##  1  ap100     1 19.8642     0     0.7336617
##  2  ap100     1 19.8642     2     0.6086769
##  3  ap100     1 19.8642     4     0.7270279
##  4  ap100     1 19.8642     6     0.7332039
##  5  ap100     1 19.8642     8     0.3253021
##  6  ap100     1 19.8642    10     0.1845512
##  7  ap100     1 19.8642    12     0.4814529
##  8  ap100     1 29.3132     0     0.1845512
##  9  ap100     1 29.3132     2     0.4814529
## 10  ap100     1 29.3132     4     0.3145866
## # ... with 28,368 more rows
# first, compare with misses to make sure we're getting good signal
# merge w/data (filter artifacts + get extra trial info)
ccn_lh = ccn_lh %>% 
  # inner join w/d, where have a new col indicating median of RT for that condition
  inner_join(d %>% group_by(subid, cond) %>% mutate(rt_bin = ntile(respRT, 3)) %>% ungroup(), 
             by=c('subid', 'run', 'onset')) %>%
  mutate(subid = factor(subid),
         cond = factor(cond))

ggplot(ccn_lh %>% group_by(group, subid, cond, time) %>% 
         summarise(ccn_sig = mean(mean_activity)) %>% 
         group_by(group, time, cond) %>% 
         summarise(mean(ccn_sig)), 
       aes(x=time, y=`mean(ccn_sig)`, color=cond, group=cond)) +
  facet_grid(.~group)+
  geom_line()

fit  = lmer(scale(hipp_tail_sig_z) ~ group * (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC)
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(hipp_tail_sig_z) ~ group * (RT_z + reps) + shockCond +  
##     (-1 + reps | subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7969.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.6861 -0.5859  0.0264  0.6555  3.0920 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.006291 0.07932       
##           reps4       0.002945 0.05427  -1.00
##  subid.1  RT_z        0.002003 0.04475       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.993705 0.99685       
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)  -4.017e-03  2.026e-02  8.944e+02  -0.198    0.843
## group1       -4.312e-03  2.026e-02  8.929e+02  -0.213    0.831
## RT_z          2.628e-02  2.128e-02  3.560e+01   1.235    0.225
## reps1         2.165e-02  2.318e-02  4.040e+01   0.934    0.356
## shockCond1    4.847e-03  1.890e-02  2.781e+03   0.256    0.798
## group1:RT_z   2.151e-02  2.128e-02  3.560e+01   1.011    0.319
## group1:reps1  2.749e-02  2.318e-02  4.040e+01   1.186    0.243
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 g1:RT_
## group1      -0.289                                   
## RT_z        -0.024  0.009                            
## reps1       -0.233  0.071  0.106                     
## shockCond1  -0.026  0.025 -0.015 -0.006              
## group1:RT_z  0.009 -0.024 -0.256 -0.029  0.014       
## group1:rps1  0.072 -0.234 -0.028 -0.234 -0.022  0.106
## collapse
dm_avg = dm %>% filter(pcorr == 1) %>%
  group_by(subid) %>%
  mutate(rt_quintile = ntile(respRT, 5)) %>%
  group_by(subid, group, rt_quintile) %>%
  summarise(ccn = mean_(hipp_tail_sig),
            count = n())

dfwc = summarySEwithin(dm_avg, measurevar="ccn", 
                       withinvars=c("rt_quintile"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: rt_quintile
dfwc
##      group rt_quintile  N        ccn   ccn_norm         sd         se
## 1  control           1 22 0.03583481 0.03440040 0.07291690 0.01554594
## 2  control           2 22 0.05225329 0.05081887 0.07497496 0.01598472
## 3  control           3 22 0.10119444 0.09976003 0.08017759 0.01709392
## 4  control           4 22 0.06906541 0.06763099 0.06650354 0.01417860
## 5  control           5 22 0.09192640 0.09049198 0.06876062 0.01465981
## 6   stress           1 20 0.08231061 0.08388847 0.10191196 0.02278821
## 7   stress           2 20 0.03821644 0.03979430 0.08003474 0.01789631
## 8   stress           3 20 0.03674231 0.03832017 0.10720746 0.02397232
## 9   stress           4 20 0.11109159 0.11266945 0.12577792 0.02812480
## 10  stress           5 20 0.06685203 0.06842989 0.07795019 0.01743019
##            ci
## 1  0.03232954
## 2  0.03324204
## 3  0.03554875
## 4  0.02948602
## 5  0.03048675
## 6  0.04769627
## 7  0.03745741
## 8  0.05017464
## 9  0.05886588
## 10 0.03648181
p2 = ggplot(dfwc, aes(x=rt_quintile, y=ccn, group=group, color=group)) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=ccn-se, 
                               ymax=ccn+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('Percent signal change')+
  xlab('RT (quintiles)')+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p2

ggsave(p2,
       filename ='~/Dropbox/Stanford/Papers/Dissertation/Figures_defense/AP_respRTXhippTail_quintile_HCrecollection.jpg',
       dpi=300, width = 6, height=4)
Break down by RT
# subtract out baseline for each trial, as this is a little variable across people (potentially due to # of SHs across groups?)
ccn_avg = ccn_lh %>% mutate(time = paste0('T',time)) %>%
  spread(key = time, value=mean_activity) %>%
  mutate(T2 = T2-T0, 
         T4 = T4 - T0,
         T6 = T6 - T0,
         T8 = T8 - T0,
         T10 = T10 - T0,
         T12 = T12 - T0) %>%
  mutate(T0 = 0) %>%
  gather(time, mean_activity, T0:T8) %>%
  mutate(time = as.numeric(substr(time, 2,3))) %>%
  dplyr::select(subid, group, onset, cond, time, mean_activity, everything()) %>%
  mutate(rt_bin=replace(rt_bin, cond=='M', 1)) %>% 
  group_by(subid, group, cond, time, rt_bin) %>% 
  summarise(ccn_sig = mean(mean_activity)) %>%
  group_by(group, time, cond, rt_bin) %>%
  summarise(mean = mean(ccn_sig), se = std.error(ccn_sig), n()) %>%
  mutate(cond_rt = paste0(cond, '-', rt_bin),
         cond_rt = replace(cond_rt, cond_rt == 'M-1', 'M'))
ccn_avg
## Source: local data frame [56 x 8]
## Groups: group, time, cond [28]
## 
## # A tibble: 56 x 8
##      group  time      cond rt_bin         mean         se `n()`
##     <fctr> <dbl>    <fctr>  <dbl>        <dbl>      <dbl> <int>
##  1 control     0         M      1  0.000000000 0.00000000    22
##  2 control     0 sourcehit      1  0.000000000 0.00000000    22
##  3 control     0 sourcehit      2  0.000000000 0.00000000    22
##  4 control     0 sourcehit      3  0.000000000 0.00000000    22
##  5 control     2         M      1 -0.020574439 0.01726235    22
##  6 control     2 sourcehit      1 -0.023227816 0.01954083    22
##  7 control     2 sourcehit      2  0.004117345 0.02226814    22
##  8 control     2 sourcehit      3 -0.026347231 0.02180056    22
##  9 control     4         M      1 -0.030093323 0.03648434    22
## 10 control     4 sourcehit      1  0.077489085 0.02676543    22
## # ... with 46 more rows, and 1 more variables: cond_rt <chr>
blues <- brewer.pal(4, "Blues")[2:4]
reds = brewer.pal(4, "Reds")[3]
colorpal = c(reds, blues)
p2 = ggplot(ccn_avg, aes(x=factor(time), y=mean, color=cond_rt, group=cond_rt)) + #group=factor(rt_bin),   color=factor(rt_bin))) +
    facet_grid(.~group) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=mean-se, 
                               ymax=mean+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('Hipp tail activity\n(% change rel onset)')+
  xlab('Time post-stimulus onset (s)') +
  guides(color=guide_legend(title="RT (tertile)")) +
  scale_color_manual(values=colorpal)
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/hippTail_bytimeXrttertile_HCrecollection_substractBL.jpg',
       dpi=150, width = 9, height=4)
p2

Bilateral networks

# bilateral now
summary(lmer(scale(CCN_sig_z) ~ group * (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_sig_z) ~ group * (RT_z + reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7936.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9333 -0.6212  0.0213  0.6472  3.6626 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       2.714e-15 5.210e-08  NaN
##  subid.1  RT_z        3.667e-03 6.055e-02     
##  subid.2  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.841e-01 9.920e-01     
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -4.777e-03  1.999e-02  2.752e+03  -0.239 0.811196    
## group1       -6.004e-03  1.999e-02  2.752e+03  -0.300 0.763983    
## RT_z          8.368e-02  2.221e-02  3.230e+01   3.768 0.000663 ***
## reps1         2.669e-02  2.020e-02  2.788e+03   1.321 0.186499    
## shockCond1    8.952e-03  1.880e-02  2.789e+03   0.476 0.634043    
## group1:RT_z   5.985e-02  2.221e-02  3.230e+01   2.695 0.011084 *  
## group1:reps1  3.438e-02  2.020e-02  2.788e+03   1.702 0.088883 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 g1:RT_
## group1      -0.292                                   
## RT_z        -0.023  0.008                            
## reps1       -0.204  0.078  0.116                     
## shockCond1  -0.026  0.024 -0.014 -0.008              
## group1:RT_z  0.008 -0.023 -0.237 -0.029  0.013       
## group1:rps1  0.079 -0.205 -0.029 -0.288 -0.021  0.115
# interaction
summary(lmer(scale(CCN_sig_z) ~ (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC %>% filter(group == 'control')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(CCN_sig_z) ~ (RT_z + reps) + shockCond + (-1 + reps | subid) +  
##     (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(group == "control")
## 
## REML criterion at convergence: 5075.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9481 -0.6062  0.0407  0.6464  3.6747 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       5.920e-25 7.694e-13  NaN
##  subid.1  RT_z        0.000e+00 0.000e+00     
##  subid.2  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.794e-01 9.897e-01     
## Number of obs: 1795, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept) -1.049e-02  2.373e-02  1.791e+03  -0.442   0.6586    
## RT_z         1.453e-01  2.357e-02  1.791e+03   6.165 8.67e-10 ***
## reps1        5.975e-02  2.398e-02  1.791e+03   2.491   0.0128 *  
## shockCond1   7.280e-04  2.337e-02  1.791e+03   0.031   0.9752    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.025              
## reps1      -0.177  0.142       
## shockCond1 -0.002 -0.002 -0.029
summary(lmer(scale(CCN_sig_z) ~ (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC %>% filter(group == 'stress')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## scale(CCN_sig_z) ~ (RT_z + reps) + shockCond + (-1 + reps | subid) +  
##     (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(group == "stress")
## 
## REML criterion at convergence: 2857.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9415 -0.6605 -0.0054  0.6354  3.2161 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.010666 0.10328       
##           reps4       0.004261 0.06527  -1.00
##  subid.1  RT_z        0.014358 0.11982       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.982433 0.99118       
## Number of obs: 1002, groups:  subid, 20
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)
## (Intercept) -1.435e-04  3.261e-02  2.408e+02  -0.004    0.996
## RT_z         2.331e-02  4.271e-02  1.580e+01   0.546    0.593
## reps1       -6.058e-03  3.841e-02  1.640e+01  -0.158    0.877
## shockCond1   2.581e-02  3.161e-02  9.957e+02   0.817    0.414
## 
## Correlation of Fixed Effects:
##            (Intr) RT_z   reps1 
## RT_z       -0.021              
## reps1      -0.266  0.086       
## shockCond1 -0.054 -0.025  0.019
# Now, double check out simple effects 
# contrasts(dCleanStandardized_HC$group) = c(0,1)
# summary(lmer(scale(CCN_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + reps|subid)+
#               (-1 + RT_z|subid)+
#               (1 |subid), 
#             data=dCleanStandardized_HC))
# 
# contrasts(dCleanStandardized_HC$group) = c(1,0)
# summary(lmer(scale(CCN_sig_z) ~ group * (RT_z + reps)  + shockCond +
#               (-1 + reps|subid)+
#               (-1 + RT_z|subid)+
#               (1 |subid), 
#             data=dCleanStandardized_HC))
# contrasts(dCleanStandardized_HC$group) = c(1,-1)


# is the RT * rep interaction significant?
summary(lmer(scale(CCN_sig_z) ~ group * (RT_z * reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (-1 + RT_z:reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(CCN_sig_z) ~ group * (RT_z * reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (-1 + RT_z:reps | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7946.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9284 -0.6236  0.0204  0.6434  3.6851 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.  Corr
##  subid    reps2       0.000e+00 0.000e+00     
##           reps4       2.915e-17 5.399e-09  NaN
##  subid.1  RT_z        0.000e+00 0.000e+00     
##  subid.2  RT_z:reps2  5.751e-03 7.583e-02     
##           RT_z:reps4  2.459e-03 4.959e-02 1.00
##  subid.3  (Intercept) 0.000e+00 0.000e+00     
##  Residual             9.838e-01 9.919e-01     
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       -7.070e-03  2.018e-02  2.752e+03  -0.350 0.726111    
## group1            -9.342e-03  2.018e-02  2.752e+03  -0.463 0.643424    
## RT_z               8.510e-02  2.258e-02  2.960e+01   3.770 0.000728 ***
## reps1              2.721e-02  2.021e-02  2.786e+03   1.346 0.178327    
## shockCond1         9.189e-03  1.880e-02  2.787e+03   0.489 0.625141    
## RT_z:reps1        -1.361e-02  2.019e-02  3.638e+02  -0.674 0.500754    
## group1:RT_z        6.266e-02  2.258e-02  2.960e+01   2.775 0.009465 ** 
## group1:reps1       3.528e-02  2.022e-02  2.786e+03   1.745 0.081099 .  
## group1:RT_z:reps1 -2.239e-02  2.019e-02  3.637e+02  -1.109 0.268047    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 RT_z:1 gr1:RT_ grp1:1
## group1      -0.290                                                  
## RT_z        -0.039  0.013                                           
## reps1       -0.209  0.079  0.118                                    
## shockCond1  -0.024  0.022 -0.015 -0.008                             
## RT_z:reps1   0.133 -0.031 -0.172 -0.039  0.009                      
## group1:RT_z  0.013 -0.039 -0.237 -0.031  0.016  0.043               
## group1:rps1  0.080 -0.209 -0.030 -0.288 -0.020  0.015  0.118        
## grp1:RT_z:1 -0.031  0.133  0.043  0.015 -0.017 -0.283 -0.172  -0.039
## DAN
summary(lmer(scale(DAN_sig_z) ~ group * (RT_z + reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_sig_z) ~ group * (RT_z + reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7938.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.0028 -0.6091  0.0026  0.6594  3.6182 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.006122 0.07824       
##           reps4       0.002809 0.05300  -1.00
##  subid.1  RT_z        0.003788 0.06155       
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.981210 0.99056       
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)  -8.639e-03  2.013e-02  8.730e+02  -0.429 0.667941    
## group1       -2.298e-03  2.013e-02  8.715e+02  -0.114 0.909156    
## RT_z          9.146e-02  2.230e-02  3.850e+01   4.102 0.000205 ***
## reps1         4.282e-02  2.299e-02  3.800e+01   1.863 0.070252 .  
## shockCond1   -3.920e-03  1.879e-02  2.780e+03  -0.209 0.834801    
## group1:RT_z   4.412e-02  2.230e-02  3.850e+01   1.979 0.055024 .  
## group1:reps1  1.641e-02  2.299e-02  3.800e+01   0.714 0.479710    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 g1:RT_
## group1      -0.289                                   
## RT_z        -0.023  0.009                            
## reps1       -0.234  0.071  0.101                     
## shockCond1  -0.026  0.025 -0.014 -0.006              
## group1:RT_z  0.009 -0.023 -0.236 -0.028  0.014       
## group1:rps1  0.072 -0.234 -0.028 -0.235 -0.022  0.101
# is the RT * rep interaction significant?
summary(lmer(scale(DAN_sig_z) ~ group * (RT_z * reps)  + shockCond +
              (-1 + reps|subid)+
              (-1 + RT_z|subid)+
               (-1 + RT_z:reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: scale(DAN_sig_z) ~ group * (RT_z * reps) + shockCond + (-1 +  
##     reps | subid) + (-1 + RT_z | subid) + (-1 + RT_z:reps | subid) +  
##     (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7950.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.9982 -0.6074  0.0035  0.6593  3.6166 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    reps2       0.006117 0.07821       
##           reps4       0.002805 0.05296  -1.00
##  subid.1  RT_z        0.000000 0.00000       
##  subid.2  RT_z:reps2  0.002860 0.05348       
##           RT_z:reps4  0.004793 0.06923  1.00 
##  subid.3  (Intercept) 0.000000 0.00000       
##  Residual             0.981757 0.99084       
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)       -8.167e-03  2.032e-02  8.940e+02  -0.402 0.687880    
## group1            -2.868e-03  2.032e-02  8.926e+02  -0.141 0.887796    
## RT_z               9.098e-02  2.243e-02  3.990e+01   4.056 0.000225 ***
## reps1              4.265e-02  2.300e-02  3.810e+01   1.854 0.071458 .  
## shockCond1        -3.923e-03  1.880e-02  2.778e+03  -0.209 0.834746    
## RT_z:reps1         4.085e-03  2.002e-02  1.544e+03   0.204 0.838340    
## group1:RT_z        4.457e-02  2.243e-02  3.990e+01   1.987 0.053806 .  
## group1:reps1       1.661e-02  2.301e-02  3.810e+01   0.722 0.474805    
## group1:RT_z:reps1 -3.922e-03  2.002e-02  1.544e+03  -0.196 0.844717    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 RT_z:1 gr1:RT_ grp1:1
## group1      -0.287                                                  
## RT_z        -0.038  0.013                                           
## reps1       -0.236  0.072  0.105                                    
## shockCond1  -0.024  0.022 -0.015 -0.006                             
## RT_z:reps1   0.135 -0.031 -0.089 -0.035  0.009                      
## group1:RT_z  0.013 -0.038 -0.238 -0.030  0.015  0.038               
## group1:rps1  0.073 -0.236 -0.029 -0.235 -0.021  0.013  0.105        
## grp1:RT_z:1 -0.031  0.134  0.038  0.013 -0.018 -0.285 -0.089  -0.035
Plot bilateral
## bilateral
dm_avg = dm %>% filter(pcorr == 1) %>%
  group_by(subid) %>%
  mutate(ccn_quintile = ntile(respRT, 5)) %>%
  group_by(subid, group, ccn_quintile, reps) %>%
  summarise(vtc_logit = mean_(CCN_sig), count = n()) %>%
  group_by(subid, group, ccn_quintile, reps) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n())%>%
  ungroup() %>%
  mutate(reps = revalue(reps, replace = c('2' = 'weak',
                                          '4' = 'strong')))

dfwc = summarySEwithin(dm_avg, measurevar="vtc_logit", 
                       withinvars=c("ccn_quintile", "reps"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: ccn_quintile
dfwc
##      group ccn_quintile   reps  N    vtc_logit vtc_logit_norm         sd
## 1  control            1 strong 22  0.057717431     0.07249908 0.09518539
## 2  control            1   weak 22 -0.051096562    -0.03631491 0.15220464
## 3  control            2 strong 22  0.065354748     0.08013640 0.07541628
## 4  control            2   weak 21 -0.001121288     0.01861256 0.14394146
## 5  control            3 strong 22  0.099638216     0.11441987 0.07699884
## 6  control            3   weak 20  0.098151890     0.11819680 0.13219196
## 7  control            4 strong 22  0.110938241     0.12571989 0.12853080
## 8  control            4   weak 22  0.056486425     0.07126808 0.11659648
## 9  control            5 strong 22  0.141587106     0.15636876 0.08045122
## 10 control            5   weak 20  0.092709770     0.11275468 0.13905546
## 11  stress            1 strong 20  0.117170530     0.09809445 0.17023626
## 12  stress            1   weak 17  0.079307913     0.06574314 0.22387668
## 13  stress            2 strong 20  0.047921529     0.02884545 0.18467113
## 14  stress            2   weak 20  0.084315743     0.06523966 0.26591751
## 15  stress            3 strong 20  0.083656394     0.06458031 0.13875341
## 16  stress            3   weak 18  0.081814608     0.06657696 0.14436736
## 17  stress            4 strong 20  0.163103773     0.14402769 0.15854473
## 18  stress            4   weak 20  0.146195426     0.12711934 0.19845885
## 19  stress            5 strong 20  0.086047377     0.06697130 0.16413163
## 20  stress            5   weak 19  0.116791153     0.10010423 0.16072191
##            se         ci
## 1  0.02029359 0.04220284
## 2  0.03245014 0.06748376
## 3  0.01607880 0.03343770
## 4  0.03141060 0.06552137
## 5  0.01641621 0.03413937
## 6  0.02955902 0.06186774
## 7  0.02740286 0.05698736
## 8  0.02485845 0.05169599
## 9  0.01715226 0.03567007
## 10 0.03109375 0.06507996
## 11 0.03806599 0.07967302
## 12 0.05429807 0.11510677
## 13 0.04129372 0.08642875
## 14 0.05946096 0.12445323
## 15 0.03102621 0.06493860
## 16 0.03402771 0.07179220
## 17 0.03545168 0.07420122
## 18 0.04437675 0.09288160
## 19 0.03670095 0.07681597
## 20 0.03687214 0.07746548
p2 = ggplot(dfwc, aes(x=ccn_quintile, y=vtc_logit, group=group, color=group)) +
    facet_grid(.~reps) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=vtc_logit-se, 
                               ymax=vtc_logit+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('CCN activity (% change)')+
  xlab('RT (quintiles)')+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/respRTXccn_quintileXrep_HCrecollection.jpg',
       dpi=150, width = 9, height=4)
p2

## collapse
dm_avg = dm %>% filter(pcorr == 1) %>%
  group_by(subid) %>%
  mutate(ccn_quintile = ntile(respRT, 5)) %>%
  group_by(subid, group, ccn_quintile, reps) %>%
  summarise(vtc_logit = mean_(CCN_sig), count = n()) %>%
  group_by(subid, group, ccn_quintile) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n())

dfwc = summarySEwithin(dm_avg, measurevar="vtc_logit", 
                       withinvars=c("ccn_quintile"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: ccn_quintile
dfwc
##      group ccn_quintile  N   vtc_logit vtc_logit_norm         sd
## 1  control            1 22 0.003310434     0.01810233 0.07102882
## 2  control            2 22 0.034525988     0.04931788 0.09007522
## 3  control            3 22 0.098644374     0.11343626 0.09696698
## 4  control            4 22 0.083712333     0.09850422 0.08659460
## 5  control            5 22 0.126286356     0.14107825 0.08776426
## 6   stress            1 20 0.096224656     0.07995358 0.16420625
## 7   stress            2 20 0.066118636     0.04984756 0.14201432
## 8   stress            3 20 0.080476036     0.06420496 0.11156895
## 9   stress            4 20 0.154649599     0.13837852 0.14243421
## 10  stress            5 20 0.104325411     0.08805433 0.10384001
##            se         ci
## 1  0.01514340 0.03149241
## 2  0.01920410 0.03993711
## 3  0.02067343 0.04299275
## 4  0.01846203 0.03839389
## 5  0.01871140 0.03891249
## 6  0.03671763 0.07685089
## 7  0.03175537 0.06646475
## 8  0.02494758 0.05221588
## 9  0.03184926 0.06666126
## 10 0.02321933 0.04859862
p2 = ggplot(dfwc, aes(x=ccn_quintile, y=vtc_logit, group=group, color=group)) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=vtc_logit-se, 
                               ymax=vtc_logit+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('CCN activity (% change)')+
  xlab('RT (quintiles)')+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/respRTXccn_quintile_HCrecollection.jpg',
       dpi=150, width = 6, height=4)
p2

2b (iii): Explore: Is hipp/vtc greater for faster high confidence memories? Or for longer RT (potentially retrieval of more things to guide associate recall) memories?

Hipp ~ RT:

# look at trial counts/subj
with(dCleanStandardized_HC, table(subid))
## subid
## ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ap110 ap111 ap113 
##    87   102    66   111   146   117   122    28    58    20    73    75 
## ap114 ap115 ap116 ap117 ap118 ap119 ap120 ap121 ap122 ap150 ap152 ap153 
##   101    77   144    84    62   112    71    33    95    66    40    31 
## ap154 ap155 ap157 ap158 ap159 ap160 ap161 ap162 ap163 ap164 ap165 ap166 
##    42    38    51    11    50    51    27    41   107    81    64    71 
## ap167 ap169 ap170 ap171 ap172 ap173 
##    38    69    74    33    20     8
data.frame(with(dCleanStandardized_HC, table(subid))) %>% summarise(mean(Freq), sd(Freq))
##   mean(Freq) sd(Freq)
## 1   66.59524 34.91387
head(dCleanStandardized_HC)
## Source: local data frame [6 x 87]
## Groups: subid [1]
## 
## # A tibble: 6 x 87
##     X.x   run trial    onset duration shockCond shockTrial  target
##   <int> <dbl> <int>    <dbl>    <dbl>    <fctr>      <int>  <fctr>
## 1     2     1     3  19.8642   9.4224      safe          0  VIOLIN
## 2     3     1     4  29.3132  11.3389      safe          0   MEDAL
## 3     4     1     5  40.6786   9.7644      safe          0  MANURE
## 4     5     1     6  50.4701   9.1180      safe          0 SARDINE
## 5    14     1    15 137.3692  10.3760      safe          0    SEAL
## 6    15     1    16 147.7725  11.9447      safe          0  SCROLL
## # ... with 79 more variables: associate <fctr>, resp <fctr>, acc <fctr>,
## #   accSpec <fctr>, respRT <dbl>, subid <fctr>, remove <lgl>,
## #   anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>, rGenHipp <dbl>,
## #   ERActUnsigned <dbl>, ERActUnsigned_infpar <dbl>, RT_z <dbl>
deq.3b<-lmer(rGenHipp ~ group*(RT_z) + reps + shockCond +
              (-1 + RT_z|subid)+
              (-1 + reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC)
# uncorrelate random slopes and intercepts
summary(deq.3b)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## rGenHipp ~ group * (RT_z) + reps + shockCond + (-1 + RT_z | subid) +  
##     (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7966.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.5190 -0.6156  0.0194  0.6350  3.7852 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    RT_z        0.004274 0.06537       
##  subid.1  reps2       0.004720 0.06870       
##           reps4       0.002204 0.04694  -1.00
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.993363 0.99668       
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)
## (Intercept) -4.488e-03  2.016e-02  1.049e+03  -0.223    0.824
## group1       5.181e-04  1.969e-02  2.753e+03   0.026    0.979
## RT_z        -2.581e-02  2.269e-02  3.640e+01  -1.137    0.263
## reps1        2.273e-02  2.183e-02  3.310e+01   1.041    0.305
## shockCond1   9.091e-04  1.890e-02  2.781e+03   0.048    0.962
## group1:RT_z  7.960e-03  2.258e-02  3.570e+01   0.353    0.726
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1
## group1      -0.281                            
## RT_z        -0.020  0.002                     
## reps1       -0.216  0.018  0.099              
## shockCond1  -0.024  0.020 -0.014 -0.012       
## group1:RT_z  0.001  0.001 -0.230 -0.003  0.016
# no interaction by rep * group?
summary(lmer(rGenHipp ~ group*(RT_z) * reps + shockCond +
              (-1 + RT_z|subid)+
              (-1 + reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## rGenHipp ~ group * (RT_z) * reps + shockCond + (-1 + RT_z | subid) +  
##     (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7981.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.5271 -0.6072  0.0193  0.6348  3.8193 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    RT_z        0.004239 0.06511       
##  subid.1  reps2       0.004548 0.06744       
##           reps4       0.002117 0.04601  -1.00
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.993552 0.99677       
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)       -5.596e-03  2.040e-02  1.081e+03  -0.274    0.784
## group1            -4.152e-03  2.040e-02  1.080e+03  -0.204    0.839
## RT_z              -2.361e-02  2.284e-02  3.690e+01  -1.034    0.308
## reps1              1.672e-02  2.245e-02  3.930e+01   0.745    0.461
## shockCond1         1.522e-04  1.891e-02  2.779e+03   0.008    0.994
## group1:RT_z        9.480e-03  2.284e-02  3.690e+01   0.415    0.680
## group1:reps1       2.784e-02  2.246e-02  3.920e+01   1.240    0.223
## RT_z:reps1        -2.193e-02  2.013e-02  2.612e+03  -1.090    0.276
## group1:RT_z:reps1  9.229e-03  2.013e-02  2.611e+03   0.458    0.647
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1 gr1:RT_ grp1:1 RT_z:1
## group1      -0.288                                                  
## RT_z        -0.038  0.013                                           
## reps1       -0.229  0.074  0.107                                    
## shockCond1  -0.024  0.022 -0.015 -0.007                             
## group1:RT_z  0.013 -0.038 -0.234 -0.030  0.015                      
## group1:rps1  0.074 -0.229 -0.030 -0.246 -0.021  0.106               
## RT_z:reps1   0.135 -0.031 -0.119 -0.036  0.009  0.040   0.013       
## grp1:RT_z:1 -0.031  0.135  0.040  0.014 -0.018 -0.120  -0.036 -0.285

Relatively higher hippocampal signal within HC recollection decisions does not track with faster/slower RTs. However, stronger encoding strength does predict faster RTs.

Plot

# look at mean trial count per bin
trial_counts = data.frame(with(dCleanStandardized_HC, 
                               table(subid, reps, hipp_quintile)))
trial_counts %>% group_by(reps, hipp_quintile) %>% summarise(mean(Freq), n())
## Source: local data frame [10 x 4]
## Groups: reps [?]
## 
## # A tibble: 10 x 4
##      reps hipp_quintile `mean(Freq)` `n()`
##    <fctr>        <fctr>        <dbl> <int>
##  1      2             1     5.809524    42
##  2      2             2     5.500000    42
##  3      2             3     5.166667    42
##  4      2             4     5.452381    42
##  5      2             5     5.023810    42
##  6      4             1     8.000000    42
##  7      4             2     7.761905    42
##  8      4             3     8.142857    42
##  9      4             4     7.809524    42
## 10      4             5     7.928571    42
## collapse
dm_avg = dm %>% filter(pcorr == 1) %>%
  group_by(subid) %>%
  mutate(hipp_quintile = ntile(hipp_sig, 5)) %>%
  group_by(subid, group, hipp_quintile, reps) %>%
  summarise(vtc_logit = mean_(respRT), count = n()) %>%
  group_by(subid, group, hipp_quintile, reps) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n())%>%
  ungroup() %>%
  mutate(reps = revalue(reps, replace = c('2' = 'weak',
                                          '4' = 'strong')))

dfwc = summarySEwithin(dm_avg, measurevar="vtc_logit", 
                       withinvars=c("hipp_quintile", "reps"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: hipp_quintile
dfwc
##      group hipp_quintile   reps  N vtc_logit vtc_logit_norm        sd
## 1  control             1 strong 22  2.237258       2.278182 0.1958658
## 2  control             1   weak 21  2.289339       2.338050 0.3229896
## 3  control             2 strong 22  2.102688       2.143613 0.2904568
## 4  control             2   weak 21  2.280425       2.329136 0.2782567
## 5  control             3 strong 22  2.217701       2.258626 0.1937109
## 6  control             3   weak 20  2.408259       2.480284 0.4150282
## 7  control             4 strong 22  2.223024       2.263949 0.2712205
## 8  control             4   weak 20  2.320787       2.392812 0.1631329
## 9  control             5 strong 21  2.171671       2.220383 0.1934599
## 10 control             5   weak 22  2.276409       2.317334 0.2412865
## 11  stress             1 strong 20  2.318344       2.256436 0.3073095
## 12  stress             1   weak 19  2.457823       2.396703 0.2060375
## 13  stress             2 strong 20  2.375300       2.313392 0.2314083
## 14  stress             2   weak 19  2.418364       2.392396 0.3736609
## 15  stress             3 strong 20  2.218369       2.156461 0.3834380
## 16  stress             3   weak 19  2.339948       2.313980 0.3275529
## 17  stress             4 strong 20  2.249552       2.187643 0.3613652
## 18  stress             4   weak 18  2.441740       2.364504 0.2830902
## 19  stress             5 strong 19  2.317853       2.240635 0.3220752
## 20  stress             5   weak 19  2.420286       2.394317 0.4217581
##            se         ci
## 1  0.04175874 0.08684205
## 2  0.07048212 0.14702313
## 3  0.06192560 0.12878134
## 4  0.06072059 0.12666093
## 5  0.04129931 0.08588661
## 6  0.09280312 0.19423916
## 7  0.05782441 0.12025244
## 8  0.03647762 0.07634853
## 9  0.04221640 0.08806187
## 10 0.05144245 0.10698044
## 11 0.06871649 0.14382527
## 12 0.04726824 0.09930689
## 13 0.05174447 0.10830242
## 14 0.08572369 0.18009879
## 15 0.08573935 0.17945452
## 16 0.07514578 0.15787543
## 17 0.08080372 0.16912413
## 18 0.06672500 0.14077743
## 19 0.07388912 0.15523528
## 20 0.09675795 0.20328090
p2 = ggplot(dfwc, aes(x=hipp_quintile, y=vtc_logit, group=group, color=group)) +
    facet_grid(.~reps) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=vtc_logit-se, 
                               ymax=vtc_logit+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('RT (s)')+
  xlab('Hippocampal activity (quintiles)')+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/respRTXhipp_quintileXrep_HCrecollection_wholehipp.jpg',
       dpi=150, width = 9, height=4)
p2

VTC ~ RT

# look at trial counts/subj
with(dCleanStandardized_HC, table(subid))
## subid
## ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ap110 ap111 ap113 
##    87   102    66   111   146   117   122    28    58    20    73    75 
## ap114 ap115 ap116 ap117 ap118 ap119 ap120 ap121 ap122 ap150 ap152 ap153 
##   101    77   144    84    62   112    71    33    95    66    40    31 
## ap154 ap155 ap157 ap158 ap159 ap160 ap161 ap162 ap163 ap164 ap165 ap166 
##    42    38    51    11    50    51    27    41   107    81    64    71 
## ap167 ap169 ap170 ap171 ap172 ap173 
##    38    69    74    33    20     8
deq.3b<-lmer(ERActUnsigned ~ group*(RT_z) + reps + shockCond +
              (-1 + RT_z|subid)+
              (-1 + reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC)
# uncorrelate random slopes and intercepts
summary(deq.3b)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: ERActUnsigned ~ group * (RT_z) + reps + shockCond + (-1 + RT_z |  
##     subid) + (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7924.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4567 -0.6545 -0.0445  0.6582  3.4570 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    RT_z        0.020752 0.14405       
##  subid.1  reps2       0.004469 0.06685       
##           reps4       0.002056 0.04535  -1.00
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.970414 0.98510       
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept) -8.306e-03  1.993e-02  1.081e+03  -0.417   0.6769  
## group1       1.805e-03  1.946e-02  2.748e+03   0.093   0.9261  
## RT_z         5.684e-02  3.060e-02  3.600e+01   1.858   0.0714 .
## reps1        3.738e-02  2.157e-02  3.970e+01   1.733   0.0908 .
## shockCond1   5.776e-03  1.873e-02  2.770e+03   0.308   0.7578  
## group1:RT_z  6.038e-02  3.052e-02  3.570e+01   1.979   0.0556 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 RT_z   reps1  shckC1
## group1      -0.281                            
## RT_z        -0.015  0.002                     
## reps1       -0.217  0.018  0.073              
## shockCond1  -0.024  0.020 -0.011 -0.012       
## group1:RT_z  0.001  0.000 -0.148 -0.006  0.012
summary(lmer(RT_z ~ (ERActUnsigned) + reps + shockCond +
              (-1 + ERActUnsigned|subid)+
              (-1 + reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC %>% filter(group == 'control')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## RT_z ~ (ERActUnsigned) + reps + shockCond + (-1 + ERActUnsigned |  
##     subid) + (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(group == "control")
## 
## REML criterion at convergence: 5040.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.2576 -0.7048 -0.1208  0.5867  3.8694 
## 
## Random effects:
##  Groups   Name          Variance Std.Dev. Corr 
##  subid    ERActUnsigned 0.018224 0.1350        
##  subid.1  reps2         0.012952 0.1138        
##           reps4         0.007413 0.0861   -1.00
##  subid.2  (Intercept)   0.000000 0.0000        
##  Residual               0.944022 0.9716        
## Number of obs: 1795, groups:  subid, 22
## 
## Fixed effects:
##                 Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)    2.167e-02  2.362e-02  3.339e+02   0.917 0.359668    
## ERActUnsigned  1.146e-01  3.806e-02  1.930e+01   3.011 0.007101 ** 
## reps1         -1.345e-01  3.268e-02  1.940e+01  -4.117 0.000563 ***
## shockCond1    -2.386e-03  2.302e-02  1.770e+03  -0.104 0.917467    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) ERActU reps1 
## ERActUnsgnd  0.001              
## reps1       -0.229 -0.006       
## shockCond1   0.000 -0.015 -0.024
summary(lmer(RT_z ~ (ERActUnsigned) + reps + shockCond +
              (-1 + ERActUnsigned|subid)+
              (-1 + reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC %>% filter(group == 'stress')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## RT_z ~ (ERActUnsigned) + reps + shockCond + (-1 + ERActUnsigned |  
##     subid) + (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_HC %>% filter(group == "stress")
## 
## REML criterion at convergence: 2834.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.4034 -0.6923 -0.1090  0.5793  4.2441 
## 
## Random effects:
##  Groups   Name          Variance Std.Dev. Corr 
##  subid    ERActUnsigned 0.024211 0.15560       
##  subid.1  reps2         0.006391 0.07994       
##           reps4         0.002720 0.05215  -1.00
##  subid.2  (Intercept)   0.000000 0.00000       
##  Residual               0.957562 0.97855       
## Number of obs: 1002, groups:  subid, 20
## 
## Fixed effects:
##                 Estimate Std. Error         df t value Pr(>|t|)   
## (Intercept)     0.026631   0.031998 325.200000   0.832  0.40586   
## ERActUnsigned  -0.001113   0.048060  14.600000  -0.023  0.98184   
## reps1          -0.129381   0.035744  11.200000  -3.620  0.00391 **
## shockCond1      0.028627   0.031132 986.800000   0.920  0.35804   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) ERActU reps1 
## ERActUnsgnd  0.009              
## reps1       -0.247 -0.035       
## shockCond1  -0.053  0.017  0.018
# interaction by rep * group?
fit1 = lmer(RT_z ~ group*(ERActUnsigned) * reps + shockCond +
              (-1 + ERActUnsigned|subid)+
              (-1 + reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_HC)
anova(deq.3b, fit1) 
## refitting model(s) with ML (instead of REML)
## Data: dCleanStandardized_HC
## Models:
## object: ERActUnsigned ~ group * (RT_z) + reps + shockCond + (-1 + RT_z | 
## object:     subid) + (-1 + reps | subid) + (1 | subid)
## ..1: RT_z ~ group * (ERActUnsigned) * reps + shockCond + (-1 + ERActUnsigned | 
## ..1:     subid) + (-1 + reps | subid) + (1 | subid)
##        Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(>Chisq)    
## object 12 7914.2 7985.4 -3945.1   7890.2                             
## ..1    15 7864.5 7953.5 -3917.2   7834.5 55.714      3  4.834e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(fit1)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## RT_z ~ group * (ERActUnsigned) * reps + shockCond + (-1 + ERActUnsigned |  
##     subid) + (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_HC
## 
## REML criterion at convergence: 7886.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.3822 -0.6994 -0.1166  0.5873  4.2232 
## 
## Random effects:
##  Groups   Name          Variance Std.Dev. Corr 
##  subid    ERActUnsigned 0.019811 0.14075       
##  subid.1  reps2         0.011384 0.10670       
##           reps4         0.005891 0.07676  -1.00
##  subid.2  (Intercept)   0.000000 0.00000       
##  Residual               0.948960 0.97415       
## Number of obs: 2797, groups:  subid, 42
## 
## Fixed effects:
##                              Estimate Std. Error         df t value
## (Intercept)                 2.385e-02  1.989e-02  7.036e+02   1.199
## group1                     -2.112e-03  1.989e-02  7.022e+02  -0.106
## ERActUnsigned               5.004e-02  3.056e-02  3.830e+01   1.637
## reps1                      -1.329e-01  2.495e-02  3.850e+01  -5.325
## shockCond1                  9.005e-03  1.851e-02  2.756e+03   0.486
## group1:ERActUnsigned        6.298e-02  3.056e-02  3.830e+01   2.060
## group1:reps1               -3.034e-03  2.496e-02  3.850e+01  -0.122
## ERActUnsigned:reps1         2.110e-02  2.030e-02  2.756e+03   1.040
## group1:ERActUnsigned:reps1 -1.598e-02  2.030e-02  2.756e+03  -0.787
##                            Pr(>|t|)    
## (Intercept)                  0.2309    
## group1                       0.9155    
## ERActUnsigned                0.1098    
## reps1                      4.63e-06 ***
## shockCond1                   0.6267    
## group1:ERActUnsigned         0.0462 *  
## group1:reps1                 0.9039    
## ERActUnsigned:reps1          0.2986    
## group1:ERActUnsigned:reps1   0.4313    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 ERActU reps1  shckC1 gr1:ERAU grp1:1 ERAU:1
## group1      -0.289                                                   
## ERActUnsgnd  0.015 -0.013                                            
## reps1       -0.245  0.067 -0.027                                     
## shockCond1  -0.026  0.025  0.000 -0.003                              
## grp1:ERActU -0.012  0.015 -0.167  0.022 -0.015                       
## group1:rps1  0.068 -0.245  0.022 -0.204 -0.021 -0.027                
## ERActUnsg:1 -0.037  0.029 -0.191  0.019  0.001  0.089   -0.018       
## grp1:ERAU:1  0.028 -0.037  0.090 -0.018  0.002 -0.191    0.019 -0.311

Plot

# look at mean trial count per bin
trial_counts = data.frame(with(dCleanStandardized_HC, 
                               table(subid, reps, vtc_quintile)))
trial_counts %>% group_by(reps, vtc_quintile) %>% summarise(mean(Freq), n())
## Source: local data frame [10 x 4]
## Groups: reps [?]
## 
## # A tibble: 10 x 4
##      reps vtc_quintile `mean(Freq)` `n()`
##    <fctr>       <fctr>        <dbl> <int>
##  1      2            1     5.619048    42
##  2      2            2     5.380952    42
##  3      2            3     5.738095    42
##  4      2            4     5.333333    42
##  5      2            5     4.880952    42
##  6      4            1     8.190476    42
##  7      4            2     7.880952    42
##  8      4            3     7.571429    42
##  9      4            4     7.928571    42
## 10      4            5     8.071429    42
## collapse
dm_avg = dm %>% filter(pcorr == 1) %>%
  group_by(subid) %>%
  mutate(hipp_quintile = ntile(vtc_logit, 5)) %>%
  group_by(subid, group, hipp_quintile, reps) %>%
  summarise(vtc_logit = mean_(respRT), count = n()) %>%
  group_by(subid, group, hipp_quintile, reps) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n())%>%
  ungroup() %>%
  mutate(reps = revalue(reps, replace = c('2' = 'weak',
                                          '4' = 'strong')))

dfwc = summarySEwithin(dm_avg, measurevar="vtc_logit", 
                       withinvars=c("hipp_quintile", "reps"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: hipp_quintile
dfwc
##      group hipp_quintile   reps  N vtc_logit vtc_logit_norm        sd
## 1  control             1 strong 21  2.126206       2.158555 0.2411987
## 2  control             1   weak 21  2.165570       2.236173 0.2564896
## 3  control             2 strong 22  2.117715       2.164387 0.1326260
## 4  control             2   weak 20  2.320329       2.398857 0.2785264
## 5  control             3 strong 22  2.175439       2.222111 0.1406605
## 6  control             3   weak 20  2.255315       2.293676 0.2611323
## 7  control             4 strong 22  2.248660       2.295332 0.1970605
## 8  control             4   weak 20  2.230069       2.308596 0.2438504
## 9  control             5 strong 22  2.268951       2.315623 0.2419571
## 10 control             5   weak 22  2.417237       2.463908 0.2859700
## 11  stress             1 strong 20  2.271066       2.197821 0.2860564
## 12  stress             1   weak 20  2.475159       2.401914 0.3026667
## 13  stress             2 strong 20  2.302424       2.229179 0.3304546
## 14  stress             2   weak 19  2.392177       2.356774 0.3661500
## 15  stress             3 strong 19  2.279786       2.244384 0.2105916
## 16  stress             3   weak 20  2.444459       2.371214 0.3227497
## 17  stress             4 strong 20  2.245060       2.171815 0.3810657
## 18  stress             4   weak 18  2.373941       2.341402 0.2911356
## 19  stress             5 strong 20  2.261222       2.187977 0.3124220
## 20  stress             5   weak 17  2.397721       2.369261 0.5264578
##            se         ci
## 1  0.05263388 0.10979235
## 2  0.05597061 0.11675265
## 3  0.02827595 0.05880306
## 4  0.06228040 0.13035438
## 5  0.02998892 0.06236536
## 6  0.05839095 0.12221367
## 7  0.04201344 0.08737173
## 8  0.05452660 0.11412549
## 9  0.05158543 0.10727776
## 10 0.06096900 0.12679198
## 11 0.06396416 0.13387852
## 12 0.06767834 0.14165239
## 13 0.07389189 0.15465749
## 14 0.08400057 0.17647864
## 15 0.04831304 0.10150192
## 16 0.07216902 0.15105149
## 17 0.08520887 0.17834422
## 18 0.06862132 0.14477833
## 19 0.06985968 0.14621799
## 20 0.12768478 0.27067963
p2 = ggplot(dfwc, aes(x=hipp_quintile, y=vtc_logit, group=group, color=group)) +
    facet_grid(.~reps) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=vtc_logit-se, 
                               ymax=vtc_logit+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('RT (s)')+
  xlab('Reinstatement strength (logits)')+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/respRTXvtc_quintileXrep_HCrecollection.jpg',
       dpi=150, width = 9, height=4)
p2

2b (iv): What about across all accurate (high AND low confidence) associative judgments (i.e., like Alan’s study)

# standardize continuous vars
dCleanStandardized_H = dm %>% filter(acc == 'H')
dCleanStandardized_H = dCleanStandardized_H %>% 
  group_by(subid) %>%
  mutate(ang_logit_z = zscore(ang_logit),
         vtc_logit_z = zscore(vtc_logit),
         hipp_logit_z = zscore(hipp_logit),
         CCN_sig_z = zscore(CCN_sig),
         DAN_sig_z = zscore(DAN_sig),
         hipp_sig_z = zscore(hipp_sig),
         hipp_tail_sig_z = zscore(hipp_tail_sig),
         hipp_quintile = ntile(hipp_sig, 5),
         CCN_quintile = ntile(CCN_sig, 5),
         DAN_quintile = ntile(DAN_sig, 5),
         hipp_tail_quintile = ntile(hipp_tail_sig, 5),
         vtc_quintile = ntile(vtc_logit, 5),
         hipp_logit_quintile = ntile(hipp_logit, 5),
         ang_quintile = ntile(ang_logit, 5),
         rt_z = zscore(respRT))

dCleanStandardized_H$rGenHipp<-scale(dCleanStandardized_H$hipp_sig_z)
dCleanStandardized_H$ERActUnsigned<-scale(dCleanStandardized_H$vtc_logit_z)
dCleanStandardized_H$ERActUnsigned_infpar<-scale(dCleanStandardized_H$ang_logit_z)
dCleanStandardized_H$RT_z<-scale(dCleanStandardized_H$rt_z)

# look at trial counts/subj
with(dCleanStandardized_H, table(subid))
## subid
## ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ap110 ap111 ap113 
##    98   116    91   124   146   129   133    70    80    75   103   108 
## ap114 ap115 ap116 ap117 ap118 ap119 ap120 ap121 ap122 ap150 ap152 ap153 
##   128   105   146    97    92   129   102    90   125   109    75    80 
## ap154 ap155 ap157 ap158 ap159 ap160 ap161 ap162 ap163 ap164 ap165 ap166 
##    74    78    92    74    73    52    73    83   121   121    94    99 
## ap167 ap169 ap170 ap171 ap172 ap173 
##    58    69   104    70    72    34
deq.4b<-lmer(RT_z ~ group*(rGenHipp) + reps + shockCond +
              (-1 + rGenHipp|subid)+
              (-1 + reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_H)
# uncorrelate random slopes and intercepts
summary(deq.4b)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: RT_z ~ group * (rGenHipp) + reps + shockCond + (-1 + rGenHipp |  
##     subid) + (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_H
## 
## REML criterion at convergence: 11278.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5469 -0.7199 -0.1082  0.5965  4.0041 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    rGenHipp    0.006601 0.08125       
##  subid.1  reps2       0.012356 0.11116       
##           reps4       0.008228 0.09071  -1.00
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.967885 0.98381       
## Number of obs: 3992, groups:  subid, 42
## 
## Fixed effects:
##                   Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)      9.065e-03  1.602e-02  1.291e+03   0.566   0.5716    
## group1          -8.642e-04  1.586e-02  3.919e+03  -0.055   0.9565    
## rGenHipp        -5.083e-02  2.043e-02  4.100e+01  -2.489   0.0169 *  
## reps1           -1.044e-01  2.234e-02  3.800e+01  -4.674 3.72e-05 ***
## shockCond1       2.376e-02  1.562e-02  3.946e+03   1.521   0.1285    
## group1:rGenHipp -4.585e-03  2.042e-02  4.100e+01  -0.225   0.8235    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1
## group1      -0.182                            
## rGenHipp     0.003  0.000                     
## reps1       -0.140  0.003 -0.024              
## shockCond1  -0.035  0.024  0.007 -0.011       
## grp1:rGnHpp  0.002  0.000 -0.134 -0.014 -0.006
# interaction by rep * group?
summary(lmer(RT_z ~ group*(rGenHipp) * reps + shockCond +
              (-1 + rGenHipp|subid)+
              (-1 + reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_H))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: RT_z ~ group * (rGenHipp) * reps + shockCond + (-1 + rGenHipp |  
##     subid) + (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_H
## 
## REML criterion at convergence: 11293.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5692 -0.7236 -0.0997  0.5913  4.0329 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    rGenHipp    0.006649 0.08154       
##  subid.1  reps2       0.010691 0.10340       
##           reps4       0.007181 0.08474  -1.00
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.968338 0.98404       
## Number of obs: 3992, groups:  subid, 42
## 
## Fixed effects:
##                         Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)            8.873e-03  1.603e-02  1.462e+03   0.553   0.5800
## group1                 3.654e-03  1.603e-02  1.459e+03   0.228   0.8197
## rGenHipp              -4.975e-02  2.053e-02  4.200e+01  -2.423   0.0198
## reps1                 -9.999e-02  2.177e-02  3.700e+01  -4.592 4.85e-05
## shockCond1             2.410e-02  1.563e-02  3.944e+03   1.542   0.1231
## group1:rGenHipp       -3.703e-03  2.053e-02  4.200e+01  -0.180   0.8577
## group1:reps1          -4.155e-02  2.177e-02  3.700e+01  -1.908   0.0641
## rGenHipp:reps1        -6.611e-03  1.604e-02  3.925e+03  -0.412   0.6803
## group1:rGenHipp:reps1 -1.296e-03  1.604e-02  3.925e+03  -0.081   0.9356
##                          
## (Intercept)              
## group1                   
## rGenHipp              *  
## reps1                 ***
## shockCond1               
## group1:rGenHipp          
## group1:reps1          .  
## rGenHipp:reps1           
## group1:rGenHipp:reps1    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 rGnHpp reps1  shckC1 gr1:GH grp1:1 rGnH:1
## group1      -0.180                                                 
## rGenHipp     0.006  0.003                                          
## reps1       -0.136  0.020 -0.024                                   
## shockCond1  -0.034  0.026  0.008 -0.011                            
## grp1:rGnHpp  0.003  0.006 -0.137 -0.012 -0.005                     
## group1:rps1  0.020 -0.136 -0.012 -0.124 -0.010 -0.024              
## rGnHpp:rps1 -0.040 -0.021 -0.085  0.006 -0.007  0.033  0.001       
## grp1:rGnH:1 -0.021 -0.040  0.033  0.001 -0.008 -0.085  0.006 -0.189
# interaction:
summary(lmer(RT_z ~ (rGenHipp) + reps + shockCond +
              (-1 + rGenHipp|subid)+
              (-1 + reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_H %>% filter(group == 'control')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: RT_z ~ (rGenHipp) + reps + shockCond + (-1 + rGenHipp | subid) +  
##     (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_H %>% filter(group == "control")
## 
## REML criterion at convergence: 6647.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5123 -0.7244 -0.0984  0.5751  3.9702 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    rGenHipp    0.008808 0.09385       
##  subid.1  reps2       0.012783 0.11306       
##           reps4       0.008880 0.09424  -1.00
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.957174 0.97835       
## Number of obs: 2361, groups:  subid, 22
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)    0.01192    0.02035  705.60000   0.586 0.558143    
## rGenHipp      -0.05348    0.02863   19.70000  -1.868 0.076731 .  
## reps1         -0.14010    0.03021   21.30000  -4.637 0.000137 ***
## shockCond1     0.01150    0.02020 2336.70000   0.569 0.569140    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) rGnHpp reps1 
## rGenHipp    0.005              
## reps1      -0.138 -0.036       
## shockCond1 -0.010  0.001 -0.020
summary(lmer(RT_z ~ (rGenHipp) + reps + shockCond +
              (-1 + rGenHipp|subid)+
              (-1 + reps|subid)+
              (1 |subid), 
            data=dCleanStandardized_H %>% filter(group == 'stress')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: RT_z ~ (rGenHipp) + reps + shockCond + (-1 + rGenHipp | subid) +  
##     (-1 + reps | subid) + (1 | subid)
##    Data: dCleanStandardized_H %>% filter(group == "stress")
## 
## REML criterion at convergence: 4632.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5702 -0.7204 -0.1071  0.6211  3.9864 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr 
##  subid    rGenHipp    0.003632 0.06027       
##  subid.1  reps2       0.005857 0.07653       
##           reps4       0.003722 0.06101  -1.00
##  subid.2  (Intercept) 0.000000 0.00000       
##  Residual             0.984554 0.99225       
## Number of obs: 1631, groups:  subid, 20
## 
## Fixed effects:
##               Estimate Std. Error         df t value Pr(>|t|)  
## (Intercept)  4.031e-03  2.482e-02  8.169e+02   0.162   0.8710  
## rGenHipp    -4.738e-02  2.829e-02  2.070e+01  -1.675   0.1090  
## reps1       -6.034e-02  2.936e-02  1.160e+01  -2.055   0.0630 .
## shockCond1   4.171e-02  2.465e-02  1.606e+03   1.692   0.0908 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr) rGnHpp reps1 
## rGenHipp    0.001              
## reps1      -0.127 -0.012       
## shockCond1 -0.061  0.014 -0.001

Plot

# trial counts are pretty good:
dm %>% filter(acc == 'H') %>%
  group_by(subid) %>%
  summarise(n())
## # A tibble: 42 x 2
##     subid `n()`
##    <fctr> <int>
##  1  ap100    98
##  2  ap101   116
##  3  ap102    91
##  4  ap103   124
##  5  ap104   146
##  6  ap105   129
##  7  ap107   133
##  8  ap108    70
##  9  ap109    80
## 10  ap110    75
## # ... with 32 more rows
dm_avg = dm %>% filter(acc == 'H') %>%
  group_by(subid) %>%
  mutate(hipp_quintile = ntile(hipp_sig, 5)) %>%
  group_by(subid, group, hipp_quintile, reps) %>%
  summarise(vtc_logit = mean_(respRT), count = n()) %>%
  group_by(subid, group, hipp_quintile, reps) %>%
  summarise(vtc_logit = mean_(vtc_logit), count = n())%>%
  ungroup() %>%
  mutate(reps = revalue(reps, replace = c('2' = 'weak',
                                          '4' = 'strong')))

dfwc = summarySEwithin(dm_avg, measurevar="vtc_logit", 
                       withinvars=c("hipp_quintile", "reps"),
                       betweenvars = c('group'),
                       idvar="subid", na.rm=TRUE, conf.interval=.95)
## Automatically converting the following non-factors to factors: hipp_quintile
dfwc
##      group hipp_quintile   reps  N vtc_logit vtc_logit_norm        sd
## 1  control             1 strong 22  2.246905       2.281643 0.1730714
## 2  control             1   weak 22  2.426256       2.460994 0.2527171
## 3  control             2 strong 22  2.206985       2.241723 0.1890151
## 4  control             2   weak 22  2.339579       2.374317 0.1671371
## 5  control             3 strong 22  2.220043       2.254781 0.1350646
## 6  control             3   weak 22  2.384549       2.419287 0.2274133
## 7  control             4 strong 22  2.225853       2.260591 0.2118445
## 8  control             4   weak 22  2.392101       2.426839 0.1808456
## 9  control             5 strong 22  2.134784       2.169521 0.1990704
## 10 control             5   weak 22  2.268831       2.303568 0.1761413
## 11  stress             1 strong 20  2.334059       2.295848 0.2078176
## 12  stress             1   weak 20  2.393061       2.354850 0.1612669
## 13  stress             2 strong 20  2.448409       2.410197 0.3184128
## 14  stress             2   weak 20  2.453996       2.415785 0.2350245
## 15  stress             3 strong 20  2.242104       2.203893 0.1825858
## 16  stress             3   weak 20  2.323713       2.285502 0.2654621
## 17  stress             4 strong 20  2.372911       2.334700 0.2260610
## 18  stress             4   weak 20  2.286386       2.248174 0.3168303
## 19  stress             5 strong 20  2.305387       2.267176 0.2882060
## 20  stress             5   weak 20  2.415349       2.377138 0.2697392
##            se         ci
## 1  0.03689894 0.07673555
## 2  0.05387947 0.11204848
## 3  0.04029815 0.08380459
## 4  0.03563375 0.07410443
## 5  0.02879587 0.05988429
## 6  0.04848468 0.10082942
## 7  0.04516540 0.09392660
## 8  0.03855641 0.08018245
## 9  0.04244196 0.08826289
## 10 0.03755345 0.07809667
## 11 0.04646943 0.09726164
## 12 0.03606037 0.07547523
## 13 0.07119928 0.14902180
## 14 0.05255308 0.10999486
## 15 0.04082743 0.08545280
## 16 0.05935912 0.12424006
## 17 0.05054877 0.10579979
## 18 0.07084541 0.14828116
## 19 0.06444482 0.13488456
## 20 0.06031551 0.12624182
p2 = ggplot(dfwc, aes(x=hipp_quintile, y=vtc_logit, group=group, color=group)) +
    facet_grid(.~reps) +
    geom_line(position=pos_dodge, size=1.5) +
    geom_errorbar(width=0, aes(ymin=vtc_logit-se, 
                               ymax=vtc_logit+se), size=1.5, position=pos_dodge) +
    geom_point(size=5, position=pos_dodge) + 
  ylab('RT (s)')+
  xlab('Hippocampal activity (quintiles)')+
  scale_color_manual(values=palette, guide = guide_legend(title = NULL))
p2

ggsave(p2,
       filename ='~/Experiments/AP/figs/respRTXhipp_quintileXrep_Hhighlowconf_wholehipp.jpg',
       dpi=150, width = 9, height=4)
p2

3) Effects of group/encoding strength on VTC reinstatement

Across old cues: pCorr ~ VTC reinstatement

Without controlling for hipp BOLD

dCleanStandardized %>% group_by(group, subid) %>%
  summarise(n()) %>%
  group_by(group)%>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    20
summary(glmer(pcorr ~ group*(ERActUnsigned) + reps + shockCond +
               (-1 + ERActUnsigned|subid) + 
               (1|subid), 
             data=dCleanStandardized, family = "binomial"))
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: 
## pcorr ~ group * (ERActUnsigned) + reps + shockCond + (-1 + ERActUnsigned |  
##     subid) + (1 | subid)
##    Data: dCleanStandardized
## 
##      AIC      BIC   logLik deviance df.resid 
##   7550.8   7605.1  -3767.4   7534.8     6615 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.8002 -0.6986 -0.3596  0.7835  5.6495 
## 
## Random effects:
##  Groups  Name          Variance Std.Dev.
##  subid   ERActUnsigned 0.04786  0.2188  
##  subid.1 (Intercept)   0.99038  0.9952  
## Number of obs: 6623, groups:  subid, 42
## 
## Fixed effects:
##                       Estimate Std. Error z value Pr(>|z|)    
## (Intercept)          -0.441580   0.156672  -2.818  0.00482 ** 
## group1                0.436634   0.156660   2.787  0.00532 ** 
## ERActUnsigned         0.326077   0.045059   7.237  4.6e-13 ***
## reps1                 0.389862   0.028704  13.582  < 2e-16 ***
## shockCond1            0.020818   0.028332   0.735  0.46246    
## group1:ERActUnsigned -0.006766   0.045038  -0.150  0.88059    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 ERActU reps1  shckC1
## group1      -0.049                            
## ERActUnsgnd -0.009  0.006                     
## reps1       -0.013  0.013 -0.017              
## shockCond1  -0.004  0.005  0.004  0.008       
## grp1:ERActU  0.006 -0.009 -0.057  0.003 -0.002

HC assoc hits: VTC reinstatement ~ group

subids_lowtrials = dm %>% 
  filter(cond == 'sourcehit') %>%
  group_by(group, subid) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), fill = list(count= 0)) %>%
  filter(count < 6) %>% 
  pull(subid) %>% unique()
subids_lowtrials
## factor(0)
## 42 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap173
d_avg = dm %>% filter(!subid %in% subids_lowtrials) %>%
  filter(cond == 'sourcehit') %>%
  group_by(group, subid) %>%
  summarise(mean=mean(vtc_logit))
with(d_avg, table(group))
## group
## control  stress 
##      22      20
# diff between groups?
bartlett.test(mean ~ group, data=d_avg)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean by group
## Bartlett's K-squared = 1.3043, df = 1, p-value = 0.2534
t.test(mean ~ group, data=d_avg, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  mean by group
## t = 1.1333, df = 40, p-value = 0.2638
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1803197  0.6406913
## sample estimates:
## mean in group control  mean in group stress 
##             0.9638410             0.7336551
d_avg %>% group_by(group) %>% summarise(mean(mean), n())
## # A tibble: 2 x 3
##     group `mean(mean)` `n()`
##    <fctr>        <dbl> <int>
## 1 control    0.9638410    22
## 2  stress    0.7336551    20
t.test(d_avg %>% filter(group == 'control') %>% pull(mean), mu = 0)
## 
##  One Sample t-test
## 
## data:  d_avg %>% filter(group == "control") %>% pull(mean)
## t = 7.9087, df = 21, p-value = 9.893e-08
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.710398 1.217284
## sample estimates:
## mean of x 
##  0.963841
t.test(d_avg %>% filter(group == 'stress') %>% pull(mean), mu = 0)
## 
##  One Sample t-test
## 
## data:  d_avg %>% filter(group == "stress") %>% pull(mean)
## t = 4.4292, df = 19, p-value = 0.0002879
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.3869672 1.0803431
## sample estimates:
## mean of x 
## 0.7336551

Does this hold in VTC excluding parahipp?

d_avg = dm %>% filter(!subid %in% subids_lowtrials) %>%
  filter(cond == 'sourcehit') %>%
  group_by(group, subid) %>%
  summarise(mean=mean(vtc_nophc_logit))
with(d_avg, table(group))
## group
## control  stress 
##      22      20
# diff between groups?
bartlett.test(mean ~ group, data=d_avg)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean by group
## Bartlett's K-squared = 1.2018, df = 1, p-value = 0.273
t.test(mean ~ group, data=d_avg, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  mean by group
## t = 1.2401, df = 40, p-value = 0.2222
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.1522148  0.6355816
## sample estimates:
## mean in group control  mean in group stress 
##             0.7124270             0.4707436
d_avg %>% group_by(group) %>% summarise(mean(mean), n())
## # A tibble: 2 x 3
##     group `mean(mean)` `n()`
##    <fctr>        <dbl> <int>
## 1 control    0.7124270    22
## 2  stress    0.4707436    20
t.test(d_avg %>% filter(group == 'control') %>% pull(mean), mu = 0)
## 
##  One Sample t-test
## 
## data:  d_avg %>% filter(group == "control") %>% pull(mean)
## t = 6.0541, df = 21, p-value = 5.23e-06
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.4677051 0.9571489
## sample estimates:
## mean of x 
##  0.712427
t.test(d_avg %>% filter(group == 'stress') %>% pull(mean), mu = 0)
## 
##  One Sample t-test
## 
## data:  d_avg %>% filter(group == "stress") %>% pull(mean)
## t = 2.9742, df = 19, p-value = 0.007794
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.1394678 0.8020194
## sample estimates:
## mean of x 
## 0.4707436

Distribution of HC assoc hit logits by subj

trial_type = 'sourcehit'
subids_lowtrials = dm %>% 
  filter(cond == trial_type) %>%
  group_by(group, subid) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), fill = list(count= 0)) %>%
  filter(count < 6) %>% 
  pull(subid) %>% unique()
subids_lowtrials
## factor(0)
## 42 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap173
d_avg = dm %>% filter(!subid %in% subids_lowtrials) %>%
  filter(cond == trial_type) %>%
  mutate(subid = factor(subid))
with(d_avg, table(subid))
## subid
## ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ap110 ap111 ap113 
##    87   102    66   111   146   117   122    28    58    20    73    75 
## ap114 ap115 ap116 ap117 ap118 ap119 ap120 ap121 ap122 ap150 ap152 ap153 
##   101    77   144    84    62   112    71    33    95    66    40    31 
## ap154 ap155 ap157 ap158 ap159 ap160 ap161 ap162 ap163 ap164 ap165 ap166 
##    42    38    51    11    50    51    27    41   107    81    64    71 
## ap167 ap169 ap170 ap171 ap172 ap173 
##    38    69    74    33    20     8
head(d_avg)
## # A tibble: 6 x 83
##     X.x   run trial    onset duration shockCond shockTrial  target
##   <int> <dbl> <int>    <dbl>    <dbl>    <fctr>      <int>  <fctr>
## 1     2     1     3  19.8642   9.4224      safe          0  VIOLIN
## 2     3     1     4  29.3132  11.3389      safe          0   MEDAL
## 3     4     1     5  40.6786   9.7644      safe          0  MANURE
## 4     5     1     6  50.4701   9.1180      safe          0 SARDINE
## 5    14     1    15 137.3692  10.3760      safe          0    SEAL
## 6    15     1    16 147.7725  11.9447      safe          0  SCROLL
## # ... with 75 more variables: associate <fctr>, resp <fctr>, acc <fctr>,
## #   accSpec <fctr>, respRT <dbl>, subid <fctr>, remove <lgl>,
## #   anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>
d_avg %>% group_by(subid, group, cond) %>% summarise(mean = mean(vtc_logit),
                                                     stdev = sd(vtc_logit)) %>%
  group_by(group, cond) %>% summarise(mean(mean), std.error(mean), n(),
                                      mean(stdev))
## Source: local data frame [2 x 6]
## Groups: group [?]
## 
## # A tibble: 2 x 6
##     group      cond `mean(mean)` `std.error(mean)` `n()` `mean(stdev)`
##    <fctr>    <fctr>        <dbl>             <dbl> <int>         <dbl>
## 1 control sourcehit    0.9638410         0.1218702    22      2.718126
## 2  stress sourcehit    0.7336551         0.1656397    20      2.682818
ggplot(d_avg, aes(x=vtc_logit, group=subid, color=subid)) + 
  geom_density() +
  facet_grid(group~.) +
  guides(colour=FALSE)

ggsave('/Volumes/group/awagner/sgagnon/AP/results/vtclogit_dist_sourcehit.png')
## Saving 7 x 5 in image
trial_type = 'itemhit_lo'
subids_lowtrials = dm %>% 
  filter(cond == trial_type) %>%
  group_by(group, subid) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), fill = list(count= 0)) %>%
  filter(count < 6) %>% 
  pull(subid) %>% unique()
subids_lowtrials
## [1] ap116 ap160 ap169
## 42 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap173
d_avg = dm %>% filter(!subid %in% subids_lowtrials) %>%
  filter(cond == trial_type) %>%
  mutate(subid = factor(subid))
with(d_avg, table(subid))
## subid
## ap100 ap101 ap102 ap103 ap105 ap107 ap108 ap109 ap110 ap111 ap113 ap114 
##    25    21    61    22    17    17    68    45   106    68    52    50 
## ap115 ap117 ap118 ap119 ap120 ap121 ap122 ap150 ap152 ap153 ap154 ap155 
##    43    25    56    26    57   108    47    72    70    86    58    77 
## ap157 ap158 ap159 ap161 ap162 ap163 ap164 ap165 ap166 ap167 ap170 ap171 
##    78   115    51    87    78    29    66    55    51    36    55    94 
## ap172 ap173 
##   124    54
head(d_avg)
## # A tibble: 6 x 83
##     X.x   run trial    onset duration shockCond shockTrial  target
##   <int> <dbl> <int>    <dbl>    <dbl>    <fctr>      <int>  <fctr>
## 1    27     1    28 272.7073  10.9982      safe          0  POWDER
## 2    28     1    29 283.7324  12.3318      safe          0   PEDAL
## 3    50     2     9  78.7475   9.8963    threat          0 SLIPPER
## 4    58     2    17 166.1540  11.1869    threat          0  CARROT
## 5    64     2    23 226.6075  11.2677    threat          0  TURTLE
## 6    72     2    31 306.9353   9.5357    threat          0     PAN
## # ... with 75 more variables: associate <fctr>, resp <fctr>, acc <fctr>,
## #   accSpec <fctr>, respRT <dbl>, subid <fctr>, remove <lgl>,
## #   anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>
d_avg %>% group_by(subid, group, cond) %>% summarise(mean = mean(vtc_logit),
                                                     stdev = sd(vtc_logit)) %>%
  group_by(group, cond) %>% summarise(mean(mean), std.error(mean), n(),
                                      mean(stdev))
## Source: local data frame [2 x 6]
## Groups: group [?]
## 
## # A tibble: 2 x 6
##     group       cond `mean(mean)` `std.error(mean)` `n()` `mean(stdev)`
##    <fctr>     <fctr>        <dbl>             <dbl> <int>         <dbl>
## 1 control itemhit_lo  -0.08993809         0.1549688    20      2.562108
## 2  stress itemhit_lo  -0.08115305         0.1128136    18      2.639425
ggplot(d_avg, aes(x=vtc_logit, group=subid, color=subid)) + 
  geom_density() +
  facet_grid(group~.) +
  guides(colour=FALSE)

ggsave('/Volumes/group/awagner/sgagnon/AP/results/vtclogit_dist_itemhit.png')
## Saving 7 x 5 in image
subids_lowtrials = dm %>% 
  filter(cond %in% c('sourcehit', 'itemhit_lo')) %>%
  mutate(cond = factor(cond)) %>%
  group_by(group, subid, cond) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), cond, fill = list(count= 0)) %>%
  filter(count < 6) %>% 
  pull(subid) %>% unique()
subids_lowtrials
## [1] ap104 ap116 ap160 ap169
## 42 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap173
d_avg = dm %>% filter(!subid %in% subids_lowtrials) %>%
  filter(cond %in% c('sourcehit', 'itemhit_lo')) %>%
  mutate(subid = factor(subid),
         cond = factor(cond))
with(d_avg, table(subid, cond))
##        cond
## subid   itemhit_lo sourcehit
##   ap100         25        87
##   ap101         21       102
##   ap102         61        66
##   ap103         22       111
##   ap105         17       117
##   ap107         17       122
##   ap108         68        28
##   ap109         45        58
##   ap110        106        20
##   ap111         68        73
##   ap113         52        75
##   ap114         50       101
##   ap115         43        77
##   ap117         25        84
##   ap118         56        62
##   ap119         26       112
##   ap120         57        71
##   ap121        108        33
##   ap122         47        95
##   ap150         72        66
##   ap152         70        40
##   ap153         86        31
##   ap154         58        42
##   ap155         77        38
##   ap157         78        51
##   ap158        115        11
##   ap159         51        50
##   ap161         87        27
##   ap162         78        41
##   ap163         29       107
##   ap164         66        81
##   ap165         55        64
##   ap166         51        71
##   ap167         36        38
##   ap170         55        74
##   ap171         94        33
##   ap172        124        20
##   ap173         54         8
head(d_avg)
## # A tibble: 6 x 83
##     X.x   run trial    onset duration shockCond shockTrial  target
##   <int> <dbl> <int>    <dbl>    <dbl>    <fctr>      <int>  <fctr>
## 1     2     1     3  19.8642   9.4224      safe          0  VIOLIN
## 2     3     1     4  29.3132  11.3389      safe          0   MEDAL
## 3     4     1     5  40.6786   9.7644      safe          0  MANURE
## 4     5     1     6  50.4701   9.1180      safe          0 SARDINE
## 5    14     1    15 137.3692  10.3760      safe          0    SEAL
## 6    15     1    16 147.7725  11.9447      safe          0  SCROLL
## # ... with 75 more variables: associate <fctr>, resp <fctr>, acc <fctr>,
## #   accSpec <fctr>, respRT <dbl>, subid <fctr>, remove <lgl>,
## #   anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>
d_avg %>% group_by(subid, group, cond) %>% summarise(mean = mean(vtc_logit),
                                                     stdev = sd(vtc_logit)) %>%
  group_by(group, cond) %>% summarise(mean(mean), std.error(mean), n(),
                                      mean(stdev))
## Source: local data frame [4 x 6]
## Groups: group [?]
## 
## # A tibble: 4 x 6
##     group       cond `mean(mean)` `std.error(mean)` `n()` `mean(stdev)`
##    <fctr>     <fctr>        <dbl>             <dbl> <int>         <dbl>
## 1 control itemhit_lo  -0.08993809         0.1549688    20      2.562108
## 2 control  sourcehit   0.97147312         0.1342191    20      2.746559
## 3  stress itemhit_lo  -0.08115305         0.1128136    18      2.639425
## 4  stress  sourcehit   0.78288505         0.1771069    18      2.682779
t.test(mean ~ cond, var.equal=TRUE, paired=TRUE, 
       d_avg %>% group_by(subid, group, cond) %>% summarise(mean = mean(vtc_logit),
                                                     stdev = sd(vtc_logit)))
## 
##  Paired t-test
## 
## data:  mean by cond
## t = -6.4858, df = 37, p-value = 1.385e-07
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -1.270299 -0.665538
## sample estimates:
## mean of the differences 
##              -0.9679187
contrasts(d_avg$cond) = c(1,-1); contrasts(d_avg$cond)
##            [,1]
## itemhit_lo    1
## sourcehit    -1
summary(lmer(mean ~ cond * group + (1|subid), 
             data=d_avg %>% group_by(subid, group, cond) %>% 
               summarise(mean = mean(vtc_logit),
                         stdev = sd(vtc_logit))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: mean ~ cond * group + (1 | subid)
##    Data: 
## d_avg %>% group_by(subid, group, cond) %>% summarise(mean = mean(vtc_logit),  
##     stdev = sd(vtc_logit))
## 
## REML criterion at convergence: 157.3
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6428 -0.4479 -0.0079  0.5931  3.2156 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.0000   0.0000  
##  Residual             0.4092   0.6397  
## Number of obs: 76, groups:  subid, 38
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   0.39582    0.07348 72.00000   5.387 8.61e-07 ***
## cond1        -0.48136    0.07348 72.00000  -6.551 7.36e-09 ***
## group1        0.04495    0.07348 72.00000   0.612    0.543    
## cond1:group1 -0.04934    0.07348 72.00000  -0.672    0.504    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) cond1  group1
## cond1        0.000              
## group1      -0.053  0.000       
## cond1:grop1  0.000 -0.053  0.000

Does trial count influence reinstatement?

d_avg = dm %>% 
  filter(cond == 'sourcehit') %>%
  filter(!subid %in% subids_lowtrials) %>%
  group_by(group, subid) %>%
  summarise(mean=mean(vtc_logit), n=n())

fit = lm(mean ~ n, data=d_avg)
summary(fit)
## 
## Call:
## lm(formula = mean ~ n, data = d_avg)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.79755 -0.26772  0.09241  0.39968  1.66764 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept) 0.730130   0.247640   2.948  0.00558 **
## n           0.002420   0.003532   0.685  0.49760   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.6783 on 36 degrees of freedom
## Multiple R-squared:  0.01287,    Adjusted R-squared:  -0.01455 
## F-statistic: 0.4695 on 1 and 36 DF,  p-value: 0.4976
plot(fit)

with(d_avg, plot(n, mean))

boxplot(d_avg$mean)

hist(fit$residuals)

# robust regression: still n.s.
# summary(rr.huber <- rlm(mean ~ poly(n,2), data=d_avg))
#dd = data.frame(summary(rr.huber)$coefficients)
#dd$p.value =  2*pt(abs(dd$t.value), summary(rr.huber)$df[2], lower.tail=FALSE)
#dd

HC assoc hits: VTC reinstatement ~ group * encoding strength

subids_lowtrials = dm %>% 
  filter(cond == 'sourcehit') %>%
  group_by(group, subid, reps) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), reps, fill = list(count= 0)) %>%
  filter(count < 6) %>% pull(subid) %>% unique()
subids_lowtrials
## [1] ap110 ap158 ap173
## 42 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap173
dm %>% filter(!subid %in% subids_lowtrials) %>%
  filter(cond == 'sourcehit') %>%
  group_by(group, subid, reps) %>%
  summarise(mean = mean(vtc_logit)) %>%
  group_by(group, reps) %>%
  summarise(mean(mean), n())
## Source: local data frame [4 x 4]
## Groups: group [?]
## 
## # A tibble: 4 x 4
##     group   reps `mean(mean)` `n()`
##    <fctr> <fctr>        <dbl> <int>
## 1 control      2    0.8457104    20
## 2 control      4    1.0123062    20
## 3  stress      2    0.5001697    19
## 4  stress      4    0.8331011    19
contrasts(dm$group)
##         [,1]
## control    1
## stress    -1
contrasts(dm$reps)
##   [,1]
## 2   -1
## 4    1
dm %>% filter(!subid %in% subids_lowtrials) %>% 
  filter(cond == 'sourcehit') %>%
  group_by(group,subid) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    20
## 2  stress    19
# control=20, stress=19

dat = dm %>% filter(!subid %in% subids_lowtrials) %>%
             filter(cond == 'sourcehit')
dat
## # A tibble: 2,758 x 83
##      X.x   run trial    onset duration shockCond shockTrial     target
##    <int> <dbl> <int>    <dbl>    <dbl>    <fctr>      <int>     <fctr>
##  1     2     1     3  19.8642   9.4224      safe          0     VIOLIN
##  2     3     1     4  29.3132  11.3389      safe          0      MEDAL
##  3     4     1     5  40.6786   9.7644      safe          0     MANURE
##  4     5     1     6  50.4701   9.1180      safe          0    SARDINE
##  5    14     1    15 137.3692  10.3760      safe          0       SEAL
##  6    15     1    16 147.7725  11.9447      safe          0     SCROLL
##  7    18     1    19 180.4083   9.3927      safe          0      CORAL
##  8    19     1    20 189.8279   9.5393      safe          0     ANCHOR
##  9    20     1    21 199.3947   9.7577      safe          0 TYPEWRITER
## 10    21     1    22 209.1792  11.6825      safe          0   PASSPORT
## # ... with 2,748 more rows, and 75 more variables: associate <fctr>,
## #   resp <fctr>, acc <fctr>, accSpec <fctr>, respRT <dbl>, subid <fctr>,
## #   remove <lgl>, anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>
summary(lmer(vtc_logit ~ group * reps +
               (1 + reps|subid), 
             data=dat,
        control=lmerControl(optimizer="Nelder_Mead",
                         optCtrl=list(maxfun=2e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ group * reps + (1 + reps | subid)
##    Data: dat
## Control: 
## lmerControl(optimizer = "Nelder_Mead", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 13504.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4855 -0.6335 -0.0398  0.6138  4.0442 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr
##  subid    (Intercept) 0.2905   0.5390       
##           reps1       0.0297   0.1723   0.08
##  Residual             7.6478   2.7655       
## Number of obs: 2758, groups:  subid, 39
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   0.83234    0.10469 35.15000   7.951  2.3e-09 ***
## group1        0.10760    0.10469 35.15000   1.028    0.311    
## reps1         0.08505    0.06344 44.33000   1.341    0.187    
## group1:reps1 -0.03762    0.06344 44.33000  -0.593    0.556    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 reps1 
## group1      -0.108              
## reps1       -0.075  0.040       
## group1:rps1  0.040 -0.075 -0.238

HC assoc hits: VTC reinstatement ~ group * run type (safe, threat)

subids_lowtrials = dm %>% 
  filter(cond == 'sourcehit') %>%
  group_by(group, subid, shockCond) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), shockCond, fill = list(count= 0)) %>%
  filter(count < 6) %>% pull(subid) %>% unique()
subids_lowtrials
## [1] ap158 ap173
## 42 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap173
dm %>% filter(!subid %in% subids_lowtrials) %>%
  filter(cond == 'sourcehit') %>%
  group_by(group, subid, shockCond) %>%
  summarise(mean = mean(vtc_logit)) %>%
  group_by(group, shockCond) %>%
  summarise(mean(mean), n())
## Source: local data frame [4 x 4]
## Groups: group [?]
## 
## # A tibble: 4 x 4
##     group shockCond `mean(mean)` `n()`
##    <fctr>    <fctr>        <dbl> <int>
## 1 control      safe    1.0297421    21
## 2 control    threat    0.9064302    21
## 3  stress      safe    0.6893210    19
## 4  stress    threat    0.7917283    19
contrasts(dm$group)
##         [,1]
## control    1
## stress    -1
contrasts(dm$shockCond)
##        [,1]
## safe      1
## threat   -1
dm %>% filter(!subid %in% subids_lowtrials) %>% 
  filter(cond == 'sourcehit') %>%
  group_by(group,subid) %>% summarise(n()) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    21
## 2  stress    19
# control=21, stress=19

# just in stress group
summary(lmer(vtc_logit ~ shockCond + (1 + shockCond|subid), 
             data=dm %>% 
             filter(!subid %in% subids_lowtrials,
                    group == 'stress') %>%
             filter(cond == 'sourcehit')),
        control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5)))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ shockCond + (1 + shockCond | subid)
##    Data: 
## dm %>% filter(!subid %in% subids_lowtrials, group == "stress") %>%  
##     filter(cond == "sourcehit")
## 
## REML criterion at convergence: 4939.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.3289 -0.6154 -0.0290  0.6510  3.2171 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr
##  subid    (Intercept) 0.413890 0.64334      
##           shockCond1  0.009807 0.09903  1.00
##  Residual             8.201927 2.86390      
## Number of obs: 994, groups:  subid, 19
## 
## Fixed effects:
##              Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)   0.75771    0.17611  18.22000   4.303 0.000418 ***
## shockCond1   -0.06971    0.09413 117.25000  -0.741 0.460467    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr)
## shockCond1 0.186
# confirm holds with regular ttest -- report this, as straightforward here
dat = dm %>% 
             filter(!subid %in% subids_lowtrials,
                    group == 'stress') %>%
             filter(cond == 'sourcehit') %>%
group_by(group, subid, shockCond) %>%
  summarise(vtc_logit = mean(vtc_logit))
bartlett.test(vtc_logit ~ shockCond, data=dat)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  vtc_logit by shockCond
## Bartlett's K-squared = 1.3469, df = 1, p-value = 0.2458
t.test(vtc_logit ~ shockCond, data=dat, var.equal=TRUE, paired=TRUE)
## 
##  Paired t-test
## 
## data:  vtc_logit by shockCond
## t = -0.58464, df = 18, p-value = 0.566
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.4704082  0.2655937
## sample estimates:
## mean of the differences 
##              -0.1024073
# interaction by group
summary(lmer(vtc_logit ~ shockCond * group + (1 + shockCond|subid), 
             data=dm %>% 
             filter(!subid %in% subids_lowtrials) %>%
             filter(cond == 'sourcehit')),
        control=lmerControl(optimizer="bobyqa",
                         optCtrl=list(maxfun=2e5))) 
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: vtc_logit ~ shockCond * group + (1 + shockCond | subid)
##    Data: dm %>% filter(!subid %in% subids_lowtrials) %>% filter(cond ==  
##     "sourcehit")
## 
## REML criterion at convergence: 13600.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.4235 -0.6332 -0.0444  0.6169  4.0419 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev. Corr
##  subid    (Intercept) 2.931e-01 0.541345     
##           shockCond1  2.595e-05 0.005094 1.00
##  Residual             7.666e+00 2.768736     
## Number of obs: 2778, groups:  subid, 40
## 
## Fixed effects:
##                     Estimate Std. Error         df t value Pr(>|t|)    
## (Intercept)        8.615e-01  1.037e-01  3.600e+01   8.309 6.82e-10 ***
## shockCond1        -2.163e-04  5.501e-02  2.678e+03  -0.004    0.997    
## group1             1.018e-01  1.037e-01  3.600e+01   0.982    0.333    
## shockCond1:group1  6.085e-02  5.501e-02  2.678e+03   1.106    0.269    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) shckC1 group1
## shockCond1  -0.006              
## group1      -0.117  0.015       
## shckCnd1:g1  0.015 -0.287 -0.006

HC assoc hits: scene vs. face/object evidence:

dcat = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_allcat_byreps_avg_46810_filtartloc_scalewithinrun.csv')
# dcat

dcat = dcat %>%
  filter(!subid %in% subids_rm,
         cond %in% c('sourcehit')) # rm subjs w/bad localizer

dim(dcat)
## [1] 8394   18
dcat = dt %>%
  mutate(onset=onset_adj, img_type=cond) %>% 
  dplyr::select(-group, -reps, -cond) %>%
  right_join(dcat, by=c('subid', 'run', 'onset')) %>% 
  filter(shock_and_post == 0)
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
dim(dcat)
## [1] 8391   47
# dcat 

str(dcat)
## 'data.frame':    8391 obs. of  47 variables:
##  $ X.x                 : int  2 2 2 3 3 3 4 4 4 5 ...
##  $ run                 : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ trial               : int  3 3 3 4 4 4 5 5 5 6 ...
##  $ onset               : num  19.9 19.9 19.9 29.3 29.3 ...
##  $ duration            : num  9.42 9.42 9.42 11.34 11.34 ...
##  $ shockCond           : Factor w/ 2 levels "safe","threat": 1 1 1 1 1 1 1 1 1 1 ...
##  $ shockTrial          : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ target              : Factor w/ 252 levels "ACCORDIAN","ACROBAT",..: 238 238 238 116 116 116 114 114 114 183 ...
##  $ associate           : Factor w/ 241 levels "\002\002","\002",..: 237 237 237 126 126 126 61 61 61 175 ...
##  $ resp                : Factor w/ 4 levels "foil","indoor",..: 2 2 2 4 4 4 4 4 4 4 ...
##  $ acc                 : Factor w/ 6 levels "CR","FA","H",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ accSpec             : Factor w/ 15 levels "CR","FAI_Hi",..: 6 6 6 8 8 8 8 8 8 8 ...
##  $ respRT              : num  1.68 1.68 1.68 1.73 1.73 ...
##  $ subid               : chr  "ap100" "ap100" "ap100" "ap100" ...
##  $ remove              : logi  NA NA NA NA NA NA ...
##  $ anxious             : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ happy               : int  2 2 2 2 2 2 2 2 2 2 ...
##  $ safe                : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ stressed            : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ life_stress         : int  4 4 4 4 4 4 4 4 4 4 ...
##  $ sleep               : num  4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 ...
##  $ cond_orig           : Factor w/ 5 levels "F_0","TI_2","TI_4",..: 2 2 2 4 4 4 4 4 4 5 ...
##  $ shock_and_post      : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ conf                : Factor w/ 3 levels "Hi","Lo","N": 1 1 1 1 1 1 1 1 1 1 ...
##  $ onset_adj           : num  19.9 19.9 19.9 29.3 29.3 ...
##  $ mem_conditions      : Factor w/ 7 levels "CR","FA","itemhit_lo",..: 6 6 6 6 6 6 6 6 6 6 ...
##  $ obj_conditions      : Factor w/ 3 levels "new","nuisance",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ onset_code          : Factor w/ 6 levels "CR","FA","itemhit",..: 6 6 6 6 6 6 6 6 6 6 ...
##  $ rt_z                : num  -0.746 -0.746 -0.746 -0.674 -0.674 ...
##  $ mem_conditions_byrep: Factor w/ 13 levels "CR-0","FA-0",..: 10 10 10 10 10 10 10 10 10 11 ...
##  $ onset_code_byrep    : Factor w/ 11 levels "CR-0","FA-0",..: 10 10 10 10 10 10 10 10 10 11 ...
##  $ img_type            : Factor w/ 3 levels "foil","indoor",..: 2 2 2 3 3 3 3 3 3 3 ...
##  $ X.y                 : int  6 7 8 9 10 11 12 13 14 15 ...
##  $ index               : int  6 7 8 9 10 11 12 13 14 15 ...
##  $ group               : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ condition           : Factor w/ 10 levels "CR-0","FA-0",..: 7 7 7 7 7 7 7 7 7 8 ...
##  $ category            : Factor w/ 3 levels "face","object",..: 1 2 3 1 2 3 1 2 3 1 ...
##  $ X0                  : num  6.81 1.4 -9.26 -1.61 -3.54 ...
##  $ X2                  : num  -0.0374 1.6988 -4.3887 -2.9945 -3.9733 ...
##  $ X4                  : num  -4.72 -2.28 5.793 -3.756 0.899 ...
##  $ X6                  : num  -1.1322 -5.8759 5.6939 0.0628 3.4763 ...
##  $ X8                  : num  -2.776 -5.292 8.645 0.743 0.324 ...
##  $ X10                 : num  -1.05 -3.67 6.49 -7.21 -1.53 ...
##  $ X12                 : num  -2.7 -3.74 6.64 -9.13 -2 ...
##  $ avg_logit           : num  -2.419 -4.279 6.655 -2.54 0.793 ...
##  $ cond                : Factor w/ 6 levels "CR","FA","itemhit_lo",..: 5 5 5 5 5 5 5 5 5 5 ...
##  $ reps                : int  2 2 2 2 2 2 2 2 2 4 ...
dcat = dcat %>% mutate(subid = factor(subid))

contrasts(dcat$group) = c(1,-1); contrasts(dcat$group)
##         [,1]
## control    1
## stress    -1
contrasts(dcat$category) = cbind(sceneVobject=c(0, 1, 0),
                                 sceneVface = c(1, 0, 0)); contrasts(dcat$category)
##        sceneVobject sceneVface
## face              0          1
## object            1          0
## place             0          0
fit = lmer(avg_logit ~ group * category + (1 + category|subid), data=dcat)
anova(fit, refit=FALSE)
## Analysis of Variance Table of type III  with  Satterthwaite 
## approximation for degrees of freedom
##                Sum Sq Mean Sq NumDF   DenDF F.value    Pr(>F)    
## group            0.01    0.01     1 199.084   0.002    0.9627    
## category       912.96  456.48     2  34.784  79.504 1.062e-13 ***
## group:category  15.47    7.74     2  34.784   1.348    0.2731    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(fit)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: avg_logit ~ group * category + (1 + category | subid)
##    Data: dcat
## 
## REML criterion at convergence: 38614.8
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.0243 -0.6288 -0.0157  0.6055  4.7028 
## 
## Random effects:
##  Groups   Name                 Variance Std.Dev. Corr       
##  subid    (Intercept)          0.3446   0.5871              
##           categorysceneVobject 0.9569   0.9782   -0.93      
##           categorysceneVface   0.5892   0.7676   -0.91  0.69
##  Residual                      5.7416   2.3962              
## Number of obs: 8391, groups:  subid, 42
## 
## Fixed effects:
##                             Estimate Std. Error       df t value Pr(>|t|)
## (Intercept)                  0.85473    0.10441 39.16000   8.186 5.18e-10
## group1                       0.10611    0.10441 39.16000   1.016    0.316
## categorysceneVobject        -1.56620    0.16872 37.93000  -9.283 2.64e-11
## categorysceneVface          -1.74503    0.13947 37.21000 -12.512 6.66e-15
## group1:categorysceneVobject -0.25480    0.16872 37.93000  -1.510    0.139
## group1:categorysceneVface   -0.06753    0.13947 37.21000  -0.484    0.631
##                                
## (Intercept)                 ***
## group1                         
## categorysceneVobject        ***
## categorysceneVface          ***
## group1:categorysceneVobject    
## group1:categorysceneVface      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##                 (Intr) group1 ctgryscnVb ctgryscnVf grp1:ctgryscnVb
## group1          -0.098                                             
## ctgryscnVbj     -0.886  0.074                                      
## ctgryscnVfc     -0.863  0.079  0.646                               
## grp1:ctgryscnVb  0.074 -0.886 -0.086     -0.054                    
## grp1:ctgryscnVf  0.079 -0.863 -0.054     -0.104      0.646

HC assoc hits: PPA ~ group

dat = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/pe_ppa_scene_graymid_limitvox.csv')
dat = dat %>% filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond))
dat
##      X      cond  hemi mask_vox regspace                        roi
## 1    0        CR bilat       39      epi ppa_scene_graymid_limitvox
## 2    2 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 3    6        CR bilat       39      epi ppa_scene_graymid_limitvox
## 4    8 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 5   12        CR bilat       39      epi ppa_scene_graymid_limitvox
## 6   14 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 7   18        CR bilat       39      epi ppa_scene_graymid_limitvox
## 8   20 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 9   24        CR bilat       39      epi ppa_scene_graymid_limitvox
## 10  26 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 11  30        CR bilat       39      epi ppa_scene_graymid_limitvox
## 12  32 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 13  36        CR bilat       39      epi ppa_scene_graymid_limitvox
## 14  38 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 15  42        CR bilat       39      epi ppa_scene_graymid_limitvox
## 16  44 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 17  48        CR bilat       39      epi ppa_scene_graymid_limitvox
## 18  50 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 19  54        CR bilat       39      epi ppa_scene_graymid_limitvox
## 20  56 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 21  60        CR bilat       39      epi ppa_scene_graymid_limitvox
## 22  62 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 23  66        CR bilat       39      epi ppa_scene_graymid_limitvox
## 24  68 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 25  72        CR bilat       39      epi ppa_scene_graymid_limitvox
## 26  74 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 27  78        CR bilat       39      epi ppa_scene_graymid_limitvox
## 28  80 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 29  84        CR bilat       39      epi ppa_scene_graymid_limitvox
## 30  86 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 31  90        CR bilat       39      epi ppa_scene_graymid_limitvox
## 32  92 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 33  96        CR bilat       39      epi ppa_scene_graymid_limitvox
## 34  98 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 35 102        CR bilat       39      epi ppa_scene_graymid_limitvox
## 36 104 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 37 108        CR bilat       39      epi ppa_scene_graymid_limitvox
## 38 110 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 39 114        CR bilat       39      epi ppa_scene_graymid_limitvox
## 40 116 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 41 120        CR bilat       39      epi ppa_scene_graymid_limitvox
## 42 122 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 43 126        CR bilat       39      epi ppa_scene_graymid_limitvox
## 44 128 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 45 132        CR bilat       39      epi ppa_scene_graymid_limitvox
## 46 134 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 47 138        CR bilat       39      epi ppa_scene_graymid_limitvox
## 48 140 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 49 144        CR bilat       39      epi ppa_scene_graymid_limitvox
## 50 146 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 51 150        CR bilat       39      epi ppa_scene_graymid_limitvox
## 52 152 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 53 156        CR bilat       39      epi ppa_scene_graymid_limitvox
## 54 158 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 55 162        CR bilat       39      epi ppa_scene_graymid_limitvox
## 56 164 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 57 168        CR bilat       39      epi ppa_scene_graymid_limitvox
## 58 170 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 59 174        CR bilat       39      epi ppa_scene_graymid_limitvox
## 60 176 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 61 180        CR bilat       39      epi ppa_scene_graymid_limitvox
## 62 182 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 63 186        CR bilat       39      epi ppa_scene_graymid_limitvox
## 64 188 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 65 192        CR bilat       39      epi ppa_scene_graymid_limitvox
## 66 194 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 67 198        CR bilat       39      epi ppa_scene_graymid_limitvox
## 68 200 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 69 204        CR bilat       39      epi ppa_scene_graymid_limitvox
## 70 206 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 71 210        CR bilat       39      epi ppa_scene_graymid_limitvox
## 72 212 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 73 216        CR bilat       39      epi ppa_scene_graymid_limitvox
## 74 218 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 75 222        CR bilat       39      epi ppa_scene_graymid_limitvox
## 76 224 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 77 228        CR bilat       39      epi ppa_scene_graymid_limitvox
## 78 230 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 79 234        CR bilat       39      epi ppa_scene_graymid_limitvox
## 80 236 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 81 240        CR bilat       39      epi ppa_scene_graymid_limitvox
## 82 242 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 83 246        CR bilat       39      epi ppa_scene_graymid_limitvox
## 84 248 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 85 252        CR bilat       39      epi ppa_scene_graymid_limitvox
## 86 254 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
## 87 258        CR bilat       39      epi ppa_scene_graymid_limitvox
## 88 260 sourcehit bilat       39      epi ppa_scene_graymid_limitvox
##     smoothing subid         value   group
## 1  unsmoothed ap100     0.2781278 control
## 2  unsmoothed ap100  2524.3881836 control
## 3  unsmoothed ap101    63.5418472 control
## 4  unsmoothed ap101  1671.2398682 control
## 5  unsmoothed ap102 -2253.8598633 control
## 6  unsmoothed ap102   754.4208984 control
## 7  unsmoothed ap103 -1441.9023438 control
## 8  unsmoothed ap103   991.7300415 control
## 9  unsmoothed ap104 -1840.0306397 control
## 10 unsmoothed ap104   420.6114807 control
## 11 unsmoothed ap105   203.5516205 control
## 12 unsmoothed ap105  1903.8507080 control
## 13 unsmoothed ap107  -767.6729736 control
## 14 unsmoothed ap107   567.1591797 control
## 15 unsmoothed ap108  -101.2654343 control
## 16 unsmoothed ap108   367.3101501 control
## 17 unsmoothed ap109  -394.9261169 control
## 18 unsmoothed ap109   678.5880127 control
## 19 unsmoothed ap110 -1345.3963623 control
## 20 unsmoothed ap110  -322.4353943 control
## 21 unsmoothed ap111 -1456.6593018 control
## 22 unsmoothed ap111   945.7440796 control
## 23 unsmoothed ap113  -137.1090851 control
## 24 unsmoothed ap113   896.7670288 control
## 25 unsmoothed ap114   372.9386291 control
## 26 unsmoothed ap114  1637.6826172 control
## 27 unsmoothed ap115  -803.8724365 control
## 28 unsmoothed ap115  1405.4901123 control
## 29 unsmoothed ap116   326.8256531 control
## 30 unsmoothed ap116  3313.5002441 control
## 31 unsmoothed ap117  -220.4937134 control
## 32 unsmoothed ap117  2175.1704102 control
## 33 unsmoothed ap118 -1649.9655762 control
## 34 unsmoothed ap118  1116.4371338 control
## 35 unsmoothed ap119 -1142.4383545 control
## 36 unsmoothed ap119  1316.4415283 control
## 37 unsmoothed ap120  -245.4828186 control
## 38 unsmoothed ap120  1640.0705566 control
## 39 unsmoothed ap121   288.2007141 control
## 40 unsmoothed ap121    65.7652969 control
## 41 unsmoothed ap122 -1537.2353516 control
## 42 unsmoothed ap122  1111.7022705 control
## 43 unsmoothed ap150   656.7203369  stress
## 44 unsmoothed ap150  1457.1075440  stress
## 45 unsmoothed ap152  -187.3688965  stress
## 46 unsmoothed ap152   707.0936890  stress
## 47 unsmoothed ap153   -57.7346115  stress
## 48 unsmoothed ap153   604.3408813  stress
## 49 unsmoothed ap154  -207.6078186  stress
## 50 unsmoothed ap154   771.2774658  stress
## 51 unsmoothed ap155   -63.5730591  stress
## 52 unsmoothed ap155   594.9816895  stress
## 53 unsmoothed ap157 -1069.8568115  stress
## 54 unsmoothed ap157   297.9955139  stress
## 55 unsmoothed ap158   194.7604370 control
## 56 unsmoothed ap158  1793.5716553 control
## 57 unsmoothed ap159  -139.6088867  stress
## 58 unsmoothed ap159  1568.5673828  stress
## 59 unsmoothed ap160  -938.8587646  stress
## 60 unsmoothed ap160   297.3102112  stress
## 61 unsmoothed ap161  -594.2133179  stress
## 62 unsmoothed ap161  -588.5639038  stress
## 63 unsmoothed ap162  -358.7315063  stress
## 64 unsmoothed ap162   675.8694458  stress
## 65 unsmoothed ap164 -2545.5439453  stress
## 66 unsmoothed ap164  1764.1096191  stress
## 67 unsmoothed ap163  -213.9288788  stress
## 68 unsmoothed ap163  2066.4916992  stress
## 69 unsmoothed ap165 -1023.0679321  stress
## 70 unsmoothed ap165   910.4725342  stress
## 71 unsmoothed ap166    72.8014145  stress
## 72 unsmoothed ap166  2252.0588379  stress
## 73 unsmoothed ap167  -159.6408691  stress
## 74 unsmoothed ap167  1698.9511719  stress
## 75 unsmoothed ap168  -534.8930664  stress
## 76 unsmoothed ap168  -792.1364746  stress
## 77 unsmoothed ap169     3.8843024  stress
## 78 unsmoothed ap169   856.3543701  stress
## 79 unsmoothed ap170  -347.3394165  stress
## 80 unsmoothed ap170  1608.4581299  stress
## 81 unsmoothed ap171    28.4471684  stress
## 82 unsmoothed ap171  1583.1534424  stress
## 83 unsmoothed ap172  -335.4015503  stress
## 84 unsmoothed ap172    23.6653557  stress
## 85 unsmoothed ap173    21.6861172  stress
## 86 unsmoothed ap173   991.1500244  stress
## 87 unsmoothed ap174   160.3838501  stress
## 88 unsmoothed ap174  1794.9483643  stress
bartlett.test(value ~ group, data=dat %>% filter(cond == 'sourcehit'))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  value by group
## Bartlett's K-squared = 0.015018, df = 1, p-value = 0.9025
t.test(value ~ group, data=dat %>% filter(cond == 'sourcehit'), var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  value by group
## t = 1.0664, df = 42, p-value = 0.2923
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -236.5547  766.6955
## sample estimates:
## mean in group control  mean in group stress 
##             1226.1457              961.0753
t.test(value ~ group, data=dat %>% filter(cond == 'CR'), var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  value by group
## t = -1.2486, df = 42, p-value = 0.2187
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -720.0389  169.6055
## sample estimates:
## mean in group control  mean in group stress 
##             -631.2824             -356.0657
# sig interaction? might be driven by decrease in CRs in ctrl, and directional increase in sh
contrasts(dat$group) = c(1,-1); contrasts(dat$group)
##         [,1]
## control    1
## stress    -1
contrasts(dat$cond) = c(-1,1); contrasts(dat$cond)
##           [,1]
## CR          -1
## sourcehit    1
summary(lmer(value ~ group * cond + (1|subid), data=dat)) # rand slope, not enough obs
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond + (1 | subid)
##    Data: dat
## 
## REML criterion at convergence: 1370
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8955 -0.5112  0.1508  0.4783  2.0861 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 201441   448.8   
##  Residual             405588   636.9   
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##              Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)   299.968     95.850  42.000   3.130  0.00318 ** 
## group1         -2.537     95.850  42.000  -0.026  0.97901    
## cond1         793.642     67.889  43.310  11.690 5.55e-15 ***
## group1:cond1  135.072     67.889  43.310   1.990  0.05297 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1
## group1      0.000              
## cond1       0.000  0.000       
## group1:cnd1 0.000  0.000  0.000

Visualize timecourse of reinstatement

by group

head(dm)
## # A tibble: 6 x 83
##     X.x   run trial   onset duration shockCond shockTrial  target
##   <int> <dbl> <int>   <dbl>    <dbl>    <fctr>      <int>  <fctr>
## 1     0     1     1  0.0191  10.6661      safe          0  BANDIT
## 2     2     1     3 19.8642   9.4224      safe          0  VIOLIN
## 3     3     1     4 29.3132  11.3389      safe          0   MEDAL
## 4     4     1     5 40.6786   9.7644      safe          0  MANURE
## 5     5     1     6 50.4701   9.1180      safe          0 SARDINE
## 6     7     1     8 69.7414   9.9338      safe          0 TOBACCO
## # ... with 75 more variables: associate <fctr>, resp <fctr>, acc <fctr>,
## #   accSpec <fctr>, respRT <dbl>, subid <fctr>, remove <lgl>,
## #   anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>
dm_time = dm %>%
  filter(cond %in% c('sourcehit')) %>%
  gather('time', 'logit_vtc', `X0`:`X12`) %>%
  mutate(time=gsub("X","",time)) %>%
  group_by(group, subid, cond, time) %>%
  summarise(mean_logit = mean_(logit_vtc)) %>%
  group_by(group, cond, time) %>%
  summarise(mean=mean_(mean_logit), sem=std.error(mean_logit), n=length(mean_logit)) %>%
  mutate(time = as.numeric(time))

p2 = ggplot(dm_time %>% filter(cond == 'sourcehit'),
            aes(x=factor(time), y=mean, group=group, color=group)) +
     geom_line(position=position_dodge(.2), size=1.5) +
    geom_point(position=position_dodge(.2), size=5) +
    geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5,
                  position=position_dodge(.2)) +
    scale_color_manual(values = palette, 
                       guide = guide_legend(title = NULL)) +
  ylab('Reinstatement strength\n(logits)') +
  xlab('Time post-stimulus onset (s)') +
   theme(legend.title=element_blank(),
        legend.position = c(.9, .8))

ggsave('~/Experiments/AP/figs/AP_reinstatement_bygroup_SH_ts.jpeg',
       dpi=150, width=5.5, height=4)
p2

## no dodge
p2 = ggplot(dm_time %>% filter(cond == 'sourcehit'),
            aes(x=factor(time), y=mean, group=group, color=group)) +
     geom_line(size=1.5) +
    geom_point(size=5) +
    geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5, alpha=.65) +
    scale_color_manual(values = palette, 
                       guide = guide_legend(title = NULL)) +
  ylab('Reinstatement strength') +
  xlab('Time post-stimulus onset (s)') +
   theme(legend.title=element_blank(),
        legend.position = c(.9, .8))
p2

ggsave('~/Experiments/AP/figs/AP_reinstatement_bygroup_SH_ts_nododge.jpeg',
       dpi=600, width=5, height=4)
p2

HC recollection: by encoding strength * group

subids_lowtrials = dm %>% 
  filter(cond == 'sourcehit') %>%
  group_by(group, subid, reps) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), reps, fill = list(count= 0)) %>%
  filter(count < 6) %>% pull(subid) %>% unique()
subids_lowtrials
## [1] ap110 ap158 ap173
## 42 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap173
with(dm %>%
  filter(cond %in% c('sourcehit')), 
  table(subid, reps))
##        reps
## subid    2  4
##   ap100 38 49
##   ap101 37 65
##   ap102 23 43
##   ap103 48 63
##   ap104 67 79
##   ap105 49 68
##   ap107 60 62
##   ap108 12 16
##   ap109 20 38
##   ap110  3 17
##   ap111 23 50
##   ap113 28 47
##   ap114 43 58
##   ap115 32 45
##   ap116 69 75
##   ap117 36 48
##   ap118 21 41
##   ap119 44 68
##   ap120 29 42
##   ap121 16 17
##   ap122 40 55
##   ap150 28 38
##   ap152 15 25
##   ap153  7 24
##   ap154 14 28
##   ap155 18 20
##   ap157 13 38
##   ap158  2  9
##   ap159 21 29
##   ap160 23 28
##   ap161  9 18
##   ap162 19 22
##   ap163 48 59
##   ap164 28 53
##   ap165 28 36
##   ap166 27 44
##   ap167 14 24
##   ap169 33 36
##   ap170 27 47
##   ap171  9 24
##   ap172  9 11
##   ap173  2  6
with(dm %>%
  filter(!subid %in% subids_lowtrials,
         cond %in% c('sourcehit')), 
  table(subid, reps))
##        reps
## subid    2  4
##   ap100 38 49
##   ap101 37 65
##   ap102 23 43
##   ap103 48 63
##   ap104 67 79
##   ap105 49 68
##   ap107 60 62
##   ap108 12 16
##   ap109 20 38
##   ap110  0  0
##   ap111 23 50
##   ap113 28 47
##   ap114 43 58
##   ap115 32 45
##   ap116 69 75
##   ap117 36 48
##   ap118 21 41
##   ap119 44 68
##   ap120 29 42
##   ap121 16 17
##   ap122 40 55
##   ap150 28 38
##   ap152 15 25
##   ap153  7 24
##   ap154 14 28
##   ap155 18 20
##   ap157 13 38
##   ap158  0  0
##   ap159 21 29
##   ap160 23 28
##   ap161  9 18
##   ap162 19 22
##   ap163 48 59
##   ap164 28 53
##   ap165 28 36
##   ap166 27 44
##   ap167 14 24
##   ap169 33 36
##   ap170 27 47
##   ap171  9 24
##   ap172  9 11
##   ap173  0  0
dm_time = dm %>%
  filter(!subid %in% subids_lowtrials) %>%
  filter(cond %in% c('sourcehit')) %>%
  gather('time', 'logit_vtc', `X0`:`X12`) %>%
  mutate(time=gsub("X","",time)) %>%
  group_by(group, subid, reps, time) %>%
  summarise(mean_logit = mean_(logit_vtc)) %>%
  group_by(group, reps, time) %>%
  summarise(mean=mean_(mean_logit), sem=std.error(mean_logit), n=length(mean_logit)) %>%
  mutate(time = as.numeric(time)) %>%
  ungroup() %>%
  mutate(reps = revalue(reps, replace = c('2' = 'weak',
                                          '4' = 'strong'))) %>%
  mutate(group = revalue(group, replace = c('control' = 'Control',
                                            'stress' = 'Stress')))

dm_time
## # A tibble: 28 x 6
##      group   reps  time        mean        sem     n
##     <fctr> <fctr> <dbl>       <dbl>      <dbl> <int>
##  1 Control   weak     0 -0.32485895 0.24148422    20
##  2 Control   weak    10 -0.03617768 0.18297077    20
##  3 Control   weak    12 -0.31620502 0.17325071    20
##  4 Control   weak     2 -0.35822065 0.18152562    20
##  5 Control   weak     4  0.53657947 0.14192816    20
##  6 Control   weak     6  1.70658865 0.28438341    20
##  7 Control   weak     8  1.17585111 0.24646744    20
##  8 Control strong     0 -0.11328754 0.09725629    20
##  9 Control strong    10  0.08498864 0.16953268    20
## 10 Control strong    12 -0.05039954 0.17108371    20
## # ... with 18 more rows
p2 = ggplot(dm_time,
            aes(x=factor(time), y=mean, group=reps, color=reps)) +
     geom_line(position=position_dodge(.2), size=1.5) +
    geom_point(position=position_dodge(.2), size=5) +
    facet_grid(.~group)+
    geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5,
                  position=position_dodge(.2)) +
    scale_color_brewer(palette = 'Set1', 
                       guide = guide_legend(title = NULL)) +
  ylab('Reinstatement strength\n(logits)') +
  xlab('Time post-stimulus onset (s)') +
  theme_classic(base_size = 18)+
  theme(legend.position = c(.5, .8),
        legend.title=element_blank(), 
        strip.text = element_text(size=18),
        strip.background = element_rect(colour="white", fill="white"))
p2

ggsave('~/Experiments/AP/figs/AP_reinstatement_bygroupXrep_SH_ts.jpeg',
       dpi=300, width=8, height=4)
ggsave('~/Dropbox/Stanford/Papers/AP/Figures/AP_supp_figure6.tiff', 
       dpi=600, width=8, height=4)
ggsave('~/Dropbox/Stanford/Papers/AP/Figures/AP_supp_figure6_150dpi.tiff', 
       dpi=150, width=8, height=4)
p2

All old conditions

head(dm)
## # A tibble: 6 x 83
##     X.x   run trial   onset duration shockCond shockTrial  target
##   <int> <dbl> <int>   <dbl>    <dbl>    <fctr>      <int>  <fctr>
## 1     0     1     1  0.0191  10.6661      safe          0  BANDIT
## 2     2     1     3 19.8642   9.4224      safe          0  VIOLIN
## 3     3     1     4 29.3132  11.3389      safe          0   MEDAL
## 4     4     1     5 40.6786   9.7644      safe          0  MANURE
## 5     5     1     6 50.4701   9.1180      safe          0 SARDINE
## 6     7     1     8 69.7414   9.9338      safe          0 TOBACCO
## # ... with 75 more variables: associate <fctr>, resp <fctr>, acc <fctr>,
## #   accSpec <fctr>, respRT <dbl>, subid <fctr>, remove <lgl>,
## #   anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>
dm_time = dm %>%
  gather('time', 'logit_vtc', `X0`:`X12`) %>%
  mutate(time=gsub("X","",time)) %>%
  group_by(group, subid, cond, time) %>%
  summarise(mean_logit = mean_(logit_vtc)) %>%
  group_by(group, cond, time) %>%
  summarise(mean=mean_(mean_logit), 
            sem=std.error(mean_logit), 
            n=length(mean_logit)) %>%
  mutate(time = as.numeric(time))

# update names for plot
unique(dm_time$cond)
## [1] itemhit_lo    M             sourcehit     sourcemiss_hi
## Levels: itemhit_lo M sourcehit sourcemiss_hi
dm_time = dm_time %>% ungroup() %>%
  mutate(cond = as.character(cond),
         cond = revalue(cond, replace = c('sourcehit' = 'HC assoc hit',
                                          'sourcemiss_hi' = 'HC assoc FA',
                                          'itemhit_lo' = 'LC item hit',
                                           'M' = 'Miss')),
         cond = factor(cond, levels=c('HC assoc hit',
                                      'HC assoc FA',
                                      'LC item hit', 
                                      'Miss'))) 
dm_time
## # A tibble: 56 x 6
##      group        cond  time        mean       sem     n
##     <fctr>      <fctr> <dbl>       <dbl>     <dbl> <int>
##  1 control LC item hit     0 -0.36392494 0.1858448    21
##  2 control LC item hit    10  0.63963679 0.3057431    21
##  3 control LC item hit    12  0.13772789 0.2791502    21
##  4 control LC item hit     2 -0.23660316 0.2516772    21
##  5 control LC item hit     4 -0.16198037 0.1261915    21
##  6 control LC item hit     6 -0.54277399 0.1894866    21
##  7 control LC item hit     8 -0.07878289 0.2009770    21
##  8 control        Miss     0 -0.16964263 0.2188713    22
##  9 control        Miss    10 -0.78060636 0.2556924    22
## 10 control        Miss    12 -0.57912127 0.2478504    22
## # ... with 46 more rows
p2 = ggplot(dm_time,
            aes(x=factor(time), y=mean, group=cond, color=cond)) +
    facet_grid(.~group)+
   geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5,
                  position=position_dodge(.5)) +
     geom_line(position=position_dodge(.5), size=1.5) +
    geom_point(position=position_dodge(.5), size=5) +
    scale_color_brewer(palette = 'RdYlBu', 
                       guide = guide_legend(title = NULL)) +
  ylab('Reinstatement strength\n(logits)') +
  xlab('Time post-stimulus onset (s)') +
   theme(legend.title=element_blank())
p2

ggsave('~/Experiments/AP/figs/AP_reinstatement_bygroup_allOLD_ts.jpeg',
       dpi=150, width=9, height=4)
p2

### All old conditions by hipp quintile

head(dm)
## # A tibble: 6 x 83
##     X.x   run trial   onset duration shockCond shockTrial  target
##   <int> <dbl> <int>   <dbl>    <dbl>    <fctr>      <int>  <fctr>
## 1     0     1     1  0.0191  10.6661      safe          0  BANDIT
## 2     2     1     3 19.8642   9.4224      safe          0  VIOLIN
## 3     3     1     4 29.3132  11.3389      safe          0   MEDAL
## 4     4     1     5 40.6786   9.7644      safe          0  MANURE
## 5     5     1     6 50.4701   9.1180      safe          0 SARDINE
## 6     7     1     8 69.7414   9.9338      safe          0 TOBACCO
## # ... with 75 more variables: associate <fctr>, resp <fctr>, acc <fctr>,
## #   accSpec <fctr>, respRT <dbl>, subid <fctr>, remove <lgl>,
## #   anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>
dm_time = dm %>%
  gather('time', 'logit_vtc', `X0`:`X12`) %>%
  mutate(time=gsub("X","",time)) %>%
  group_by(group, subid, cond, time, hipp_quintile) %>%
  summarise(mean_logit = mean_(logit_vtc)) %>%
  group_by(group, cond, time, hipp_quintile) %>%
  summarise(mean=mean_(mean_logit), 
            sem=std.error(mean_logit), 
            n=length(mean_logit)) %>%
  ungroup() %>%
  mutate(time = as.numeric(time))

# update names for plot
unique(dm_time$cond)
## [1] itemhit_lo    M             sourcehit     sourcemiss_hi
## Levels: itemhit_lo M sourcehit sourcemiss_hi
dm_time = dm_time %>% ungroup() %>%
  mutate(cond = as.character(cond),
         cond = revalue(cond, replace = c('sourcehit' = 'HC assoc hit',
                                          'sourcemiss_hi' = 'HC assoc FA',
                                          'itemhit_lo' = 'LC item hit',
                                           'M' = 'Miss')),
         cond = factor(cond, levels=c('HC assoc hit',
                                      'HC assoc FA',
                                      'LC item hit', 
                                      'Miss'))) 
dm_time
## # A tibble: 280 x 7
##      group        cond  time hipp_quintile       mean       sem     n
##     <fctr>      <fctr> <dbl>         <int>      <dbl>     <dbl> <int>
##  1 control LC item hit     0             1 -0.1617156 0.2308486    21
##  2 control LC item hit     0             2 -0.1324871 0.2991220    20
##  3 control LC item hit     0             3 -0.1092320 0.3948682    20
##  4 control LC item hit     0             4 -1.0374211 0.4837502    20
##  5 control LC item hit     0             5 -0.6314236 0.6985017    19
##  6 control LC item hit    10             1  0.3893503 0.3336490    21
##  7 control LC item hit    10             2  0.5862498 0.3381496    20
##  8 control LC item hit    10             3  0.4088204 0.3360453    20
##  9 control LC item hit    10             4  0.9625374 0.6375035    20
## 10 control LC item hit    10             5  1.3195959 0.5829748    19
## # ... with 270 more rows
p2 = ggplot(dm_time,
            aes(x=factor(time), y=mean, group=cond, color=cond)) +
    facet_grid(group~hipp_quintile)+
   geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5,
                  position=position_dodge(.5)) +
     geom_line(position=position_dodge(.5), size=1.5) +
    geom_point(position=position_dodge(.5), size=5) +
    scale_color_brewer(palette = 'RdYlBu', 
                       guide = guide_legend(title = NULL)) +
  ylab('Reinstatement strength\n(logits)') +
  xlab('Time post-stimulus onset (s)') +
   theme(legend.title=element_blank())
p2

ggsave('~/Experiments/AP/figs/AP_reinstatement_bygroupXhippquintile_allOLD_ts.jpeg',
       dpi=150, width=20, height=9)
p2

p2 = ggplot(dm_time,
            aes(x=factor(time), y=mean, group=factor(hipp_quintile), color=factor(hipp_quintile))) +
    facet_grid(group~cond)+
      geom_hline(yintercept = 0, linetype=2)+

   geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5,
                  position=position_dodge(.5)) +
     geom_line(position=position_dodge(.5), size=1.5) +
    geom_point(position=position_dodge(.5), size=5) +
    scale_color_brewer(palette = 'RdYlBu', 
                       guide = guide_legend(title = NULL)) +
  ylab('Reinstatement strength\n(logits)') +
  xlab('Time post-stimulus onset (s)') +
   theme(legend.title=element_blank())
ggsave('~/Experiments/AP/figs/AP_reinstatement_bygroupXhippquintile_allOLD_ts_v2.jpeg',
       dpi=150, width=20, height=9)
p2

p2 = ggplot(dm_time,
            aes(x=factor(time), y=mean, group=group, color=group)) +
    facet_grid(cond~hipp_quintile)+
  geom_hline(yintercept = 0, linetype=2)+
   geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5,
                  position=position_dodge(.5)) +
     geom_line(position=position_dodge(.5), size=1.5) +
    geom_point(position=position_dodge(.5), size=5) +
    scale_color_manual(values=palette, 
                       guide = guide_legend(title = NULL)) +
  ylab('Reinstatement strength\n(logits)') +
  xlab('Time post-stimulus onset (s)') +
   theme(legend.title=element_blank()) 
p2

ggsave('~/Experiments/AP/figs/AP_reinstatement_bygroupXhippquintile_allOLD_ts_v3.jpeg',
       dpi=150, width=15, height=15)
p2

head(dm)
## # A tibble: 6 x 83
##     X.x   run trial   onset duration shockCond shockTrial  target
##   <int> <dbl> <int>   <dbl>    <dbl>    <fctr>      <int>  <fctr>
## 1     0     1     1  0.0191  10.6661      safe          0  BANDIT
## 2     2     1     3 19.8642   9.4224      safe          0  VIOLIN
## 3     3     1     4 29.3132  11.3389      safe          0   MEDAL
## 4     4     1     5 40.6786   9.7644      safe          0  MANURE
## 5     5     1     6 50.4701   9.1180      safe          0 SARDINE
## 6     7     1     8 69.7414   9.9338      safe          0 TOBACCO
## # ... with 75 more variables: associate <fctr>, resp <fctr>, acc <fctr>,
## #   accSpec <fctr>, respRT <dbl>, subid <fctr>, remove <lgl>,
## #   anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>
dm_time = dm %>%
  group_by(group, subid, cond, hipp_quintile) %>%
  summarise(mean_logit = mean_(vtc_logit)) %>%
  group_by(group, cond, hipp_quintile) %>%
  summarise(mean=mean_(mean_logit), 
            sem=std.error(mean_logit), 
            n=length(mean_logit)) %>%
  ungroup()

# update names for plot
dm_time = dm_time %>% ungroup() %>%
  mutate(cond = as.character(cond),
         cond = revalue(cond, replace = c('sourcehit' = 'HC assoc hit',
                                          'sourcemiss_hi' = 'HC assoc FA',
                                          'itemhit_lo' = 'LC item hit',
                                           'M' = 'Miss')),
         cond = factor(cond, levels=c('HC assoc hit',
                                      'HC assoc FA',
                                      'LC item hit', 
                                      'Miss'))) 
dm_time
## # A tibble: 40 x 6
##      group        cond hipp_quintile        mean       sem     n
##     <fctr>      <fctr>         <int>       <dbl>     <dbl> <int>
##  1 control LC item hit             1 -0.38368700 0.2592430    21
##  2 control LC item hit             2 -0.25445570 0.2815357    20
##  3 control LC item hit             3 -0.02095554 0.1722509    20
##  4 control LC item hit             4  0.42818584 0.2498491    20
##  5 control LC item hit             5  1.03541320 0.3938372    19
##  6 control        Miss             1 -2.28335646 0.3236401    22
##  7 control        Miss             2 -1.79483084 0.3340072    21
##  8 control        Miss             3 -1.10737456 0.3871727    21
##  9 control        Miss             4 -0.44900746 0.3308352    19
## 10 control        Miss             5  0.36367873 0.4300350    17
## # ... with 30 more rows
p2 = ggplot(dm_time,
            aes(x=factor(hipp_quintile), y=mean, group=group, color=group)) +
    facet_grid(.~cond)+
  geom_hline(yintercept = 0, linetype=2)+
   geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5,
                  position=position_dodge(.5)) +
     geom_line(position=position_dodge(.5), size=1.5) +
    geom_point(position=position_dodge(.5), size=5) +
    scale_color_manual(values=palette, 
                       guide = guide_legend(title = NULL)) +
  ylab('Reinstatement strength\n(logits)') +
  xlab('Hipp quintile') +
   theme(legend.title=element_blank()) 
p2

ggsave('~/Experiments/AP/figs/AP_reinstatement_bygroupXhippquintile_allOLD_v4.jpeg',
       dpi=150, width=15, height=8)
p2

All old conditions by hipp quintile (collapse across cond)

head(dm)
## # A tibble: 6 x 83
##     X.x   run trial   onset duration shockCond shockTrial  target
##   <int> <dbl> <int>   <dbl>    <dbl>    <fctr>      <int>  <fctr>
## 1     0     1     1  0.0191  10.6661      safe          0  BANDIT
## 2     2     1     3 19.8642   9.4224      safe          0  VIOLIN
## 3     3     1     4 29.3132  11.3389      safe          0   MEDAL
## 4     4     1     5 40.6786   9.7644      safe          0  MANURE
## 5     5     1     6 50.4701   9.1180      safe          0 SARDINE
## 6     7     1     8 69.7414   9.9338      safe          0 TOBACCO
## # ... with 75 more variables: associate <fctr>, resp <fctr>, acc <fctr>,
## #   accSpec <fctr>, respRT <dbl>, subid <fctr>, remove <lgl>,
## #   anxious <int>, happy <int>, safe <int>, stressed <int>,
## #   life_stress <int>, sleep <dbl>, cond_orig <fctr>,
## #   shock_and_post <int>, conf <fctr>, onset_adj <dbl>,
## #   mem_conditions <fctr>, obj_conditions <fctr>, onset_code <fctr>,
## #   rt_z <dbl>, mem_conditions_byrep <fctr>, onset_code_byrep <fctr>,
## #   img_type <fctr>, X.y <int>, index <int>, group <fctr>,
## #   condition <fctr>, category <fctr>, X0 <dbl>, X2 <dbl>, X4 <dbl>,
## #   X6 <dbl>, X8 <dbl>, X10 <dbl>, X12 <dbl>, avg_logit <dbl>,
## #   cond <fctr>, reps <fctr>, pcorr <fctr>, vtc_logit <dbl>,
## #   imgType <fctr>, hipp_sig <dbl>, hipp_tail_sig <dbl>, DAN_sig <dbl>,
## #   CCN_sig <dbl>, rsp_sig <dbl>, angular_lh_sig <dbl>, DAN_lh_sig <dbl>,
## #   CCN_lh_sig <dbl>, ang_logit <dbl>, hipp_logit <dbl>,
## #   vtc_nophc_logit <dbl>, ang_logit_z <dbl>, vtc_logit_z <dbl>,
## #   hipp_logit_z <dbl>, CCN_sig_z <dbl>, rsp_sig_z <dbl>, DAN_sig_z <dbl>,
## #   angular_lh_sig_z <dbl>, CCN_lh_sig_z <dbl>, DAN_lh_sig_z <dbl>,
## #   hipp_sig_z <dbl>, hipp_tail_sig_z <dbl>, hipp_quintile <int>,
## #   rsp_quintile <int>, CCN_quintile <int>, DAN_quintile <int>,
## #   angular_lh_sig_quintile <int>, CCN_lh_quintile <int>,
## #   DAN_lh_quintile <int>, hipp_tail_quintile <int>, vtc_quintile <int>,
## #   hipp_logit_quintile <int>, ang_quintile <int>
dm_time = dm %>%
  gather('time', 'logit_vtc', `X0`:`X12`) %>%
  mutate(time=gsub("X","",time)) %>%
  group_by(group, subid, time, hipp_quintile) %>%
  summarise(mean_logit = mean_(logit_vtc)) %>%
  group_by(group, time, hipp_quintile) %>%
  summarise(mean=mean_(mean_logit), 
            sem=std.error(mean_logit), 
            n=length(mean_logit)) %>%
  ungroup() %>%
  mutate(time = as.numeric(time))

blues <- brewer.pal(6, "Blues")[2:6]
p2 = ggplot(dm_time,
            aes(x=factor(time), y=mean, group=hipp_quintile, color=factor(hipp_quintile))) +
    facet_grid(.~group)+
      geom_hline(yintercept = 0, linetype=2)+
   geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5,
                  position=position_dodge(.5)) +
     geom_line(position=position_dodge(.5), size=1.5) +
    geom_point(position=position_dodge(.5), size=5) +
    scale_color_manual(values = blues,
                       guide = guide_legend(title = NULL)) +
  ylab('Reinstatement strength\n(logits)') +
  xlab('Time post-stimulus onset (s)') +
   theme(legend.title=element_blank())
p2

ggsave('~/Experiments/AP/figs/AP_reinstatement_bygroupXhippquintile_collapse_allOLD_ts.jpeg',
       dpi=150, width=9, height=5)
p2

p2 = ggplot(dm_time,
            aes(x=factor(time), y=mean, group=group, color=group)) +
    facet_grid(.~hipp_quintile)+
      geom_hline(yintercept = 0, linetype=2)+
   geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5,
                  position=position_dodge(.5)) +
     geom_line(position=position_dodge(.5), size=1.5) +
    geom_point(position=position_dodge(.5), size=5) +
    scale_color_manual(values = palette,
                       guide = guide_legend(title = NULL)) +
  ylab('Reinstatement strength\n(logits)') +
  xlab('Time post-stimulus onset (s)') +
   theme(legend.title=element_blank())
p2

ggsave('~/Experiments/AP/figs/AP_reinstatement_bygroupXhippquintile_collapse_allOLD_ts_v2.jpeg',
       dpi=150, width=15, height=5)
p2

3b) Effects of group/encoding strength on inferior parietal reinstatement

Note that these analyses are using strict criterion that VTC reinstatement F1 score can’t be an outlier (control = 22, stress = 20); see below for analyses allowing 1 participant with non-outlier inferior parietal F1 score to be included (control = 22, stress = 21).

HC assoc hits: infparietal reinstatement ~ group

subids_lowtrials = dm %>% 
  filter(cond == 'sourcehit') %>%
  group_by(group, subid) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), fill = list(count= 0)) %>%
  filter(count < 6) %>% 
  pull(subid) %>% unique()
subids_lowtrials
## factor(0)
## 42 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap173
d_avg = dm %>% filter(!subid %in% subids_lowtrials) %>%
  filter(cond == 'sourcehit') %>%
  group_by(group, subid) %>%
  summarise(mean=mean(ang_logit))
with(d_avg, table(group))
## group
## control  stress 
##      22      20
# diff between groups?
bartlett.test(mean ~ group, data=d_avg)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean by group
## Bartlett's K-squared = 0.92568, df = 1, p-value = 0.336
t.test(mean ~ group, data=d_avg, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  mean by group
## t = 0.64016, df = 40, p-value = 0.5257
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.3048895  0.5875713
## sample estimates:
## mean in group control  mean in group stress 
##             0.3410088             0.1996679
d_avg %>% group_by(group) %>% summarise(mean(mean), n())
## # A tibble: 2 x 3
##     group `mean(mean)` `n()`
##    <fctr>        <dbl> <int>
## 1 control    0.3410088    22
## 2  stress    0.1996679    20
t.test(d_avg %>% filter(group == 'control') %>% pull(mean), mu = 0)
## 
##  One Sample t-test
## 
## data:  d_avg %>% filter(group == "control") %>% pull(mean)
## t = 2.5122, df = 21, p-value = 0.02024
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.05871977 0.62329777
## sample estimates:
## mean of x 
## 0.3410088
t.test(d_avg %>% filter(group == 'stress') %>% pull(mean), mu = 0)
## 
##  One Sample t-test
## 
## data:  d_avg %>% filter(group == "stress") %>% pull(mean)
## t = 1.1276, df = 19, p-value = 0.2735
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.1709514  0.5702871
## sample estimates:
## mean of x 
## 0.1996679

4) Hipp peak from whole-brain analysis

Sphere from control>stress, SH > CR

##         [,1]
## control    1
## stress    -1
##           [,1]
## CR          -1
## sourcehit    1
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond + (1 | subid)
##    Data: dat
## 
## REML criterion at convergence: 1241.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8742 -0.5136  0.1295  0.5402  2.3126 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 79656    282.2   
##  Residual             68301    261.3   
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##              Estimate Std. Error     df t value Pr(>|t|)    
## (Intercept)    219.00      50.86  42.00   4.306 9.76e-05 ***
## group1          42.52      50.86  42.00   0.836   0.4078    
## cond1          199.09      27.86  43.03   7.146 7.88e-09 ***
## group1:cond1    68.31      27.86  43.03   2.452   0.0183 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1
## group1      0.000              
## cond1       0.000  0.000       
## group1:cnd1 0.000  0.000  0.000
## 
##  Two Sample t-test
## 
## data:  value by group
## t = 2.0628, df = 42, p-value = 0.04535
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##    4.808099 438.516200
## sample estimates:
## mean in group control  mean in group stress 
##              528.9209              307.2588
## 
##  Two Sample t-test
## 
## data:  value by group
## t = -0.41617, df = 42, p-value = 0.6794
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -301.6367  198.4988
## sample estimates:
## mean in group control  mean in group stress 
##             -5.884154             45.684789
## # A tibble: 4 x 5
##     group         cond      value      sem     n
##    <fctr>       <fctr>      <dbl>    <dbl> <int>
## 1 control           CR  -5.884154 89.14745    22
## 2 control HC
## assoc hit 528.920947 70.92192    22
## 3  stress           CR  45.684789 86.06576    22
## 4  stress HC
## assoc hit 307.258798 80.72654    22

## # A tibble: 88 x 4
##     subid   group         cond       mean
##    <fctr>  <fctr>       <fctr>      <dbl>
##  1  ap100 control           CR -395.94870
##  2  ap100 control HC
## assoc hit  379.93707
##  3  ap101 control           CR  319.92365
##  4  ap101 control HC
## assoc hit  990.58691
##  5  ap102 control           CR  107.35379
##  6  ap102 control HC
## assoc hit  891.54816
##  7  ap103 control           CR -519.10510
##  8  ap103 control HC
## assoc hit   90.65915
##  9  ap104 control           CR -415.79956
## 10  ap104 control HC
## assoc hit  -99.19929
## # ... with 78 more rows

## Warning: Ignoring unknown aesthetics: y

5) Predictors of HC accuracy

Calculate P(accurate|respond “high conf source” to old item)

with(dtest %>% filter(reps > 0,
                      conf == 'Hi'), table(subj_status, acc))
##            acc
## subj_status   CR   FA    H    M no response   SM
##         old    0    0 3025    0           0  706
dtest %>% 
  filter(subj_status == 'old',
         reps > 0, # old item
         conf == 'Hi') %>% dim()
## [1] 3731   15
dtest %>% 
  filter(subj_status == 'old',
         reps > 0, # old item
         conf == 'Hi',
         acc_num == 1) %>% dim() # 3025
## [1] 3025   15
dat = dtest %>% 
  filter(subj_status == 'old',
         reps > 0, # old item
         conf == 'Hi') %>%
  group_by(subid, group) %>%
  summarise(mean_acc = mean(acc_num), sum=sum(acc_num), count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), fill = list(mean_acc=0,
                                                    count=0))
dat
## # A tibble: 47 x 5
##     subid   group  mean_acc   sum count
##    <fctr>  <fctr>     <dbl> <dbl> <dbl>
##  1  ap100 control 0.8725490    89   102
##  2  ap101 control 0.9375000   105   112
##  3  ap102 control 0.7010309    68    97
##  4  ap103 control 0.8968254   113   126
##  5  ap104 control 0.9130435   147   161
##  6  ap105 control 0.8623188   119   138
##  7  ap106 control 0.5087719    29    57
##  8  ap107 control 0.8802817   125   142
##  9  ap108 control 0.7073171    29    41
## 10  ap109 control 0.6489362    61    94
## # ... with 37 more rows
# filter out subjs who don't have more than 5 "old" responses to old cues
dim(dat) # all subjs included
## [1] 47  5
dat %>% filter(count < 6) 
## # A tibble: 1 x 5
##    subid  group mean_acc   sum count
##   <fctr> <fctr>    <dbl> <dbl> <dbl>
## 1  ap151 stress      0.6     3     5
rm_subids = dat %>% filter(count < 6) %>% pull(subid) %>% unique(); rm_subids
## [1] ap151
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
rm_subids # ap151
## [1] ap151
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
dat = dat %>% filter(!subid %in% rm_subids)

# logit transform accuracy for stats (since upper bounded at 1)
dat %>% group_by(subid, group) %>% 
  summarise(mean_acc = mean(mean_acc), n()) %>% 
  group_by(group) %>% 
  summarise(mean(mean_acc), n())
## # A tibble: 2 x 3
##     group `mean(mean_acc)` `n()`
##    <fctr>            <dbl> <int>
## 1 control        0.8185684    23
## 2  stress        0.7387830    23
hist(dat$mean_acc)

dat = dat %>% mutate(mean_acc_logit = car::logit(mean_acc))
hist(dat$mean_acc_logit)

boxplot(dat$mean_acc_logit)

Across all subjs (regardless of scan-criteria) effect of group on acc?

bartlett.test(mean_acc_logit ~ group, data=dat)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean_acc_logit by group
## Bartlett's K-squared = 0.14041, df = 1, p-value = 0.7079
t.test(mean_acc_logit ~ group, data=dat, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  mean_acc_logit by group
## t = 1.9585, df = 44, p-value = 0.05653
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.01457236  1.01850230
## sample estimates:
## mean in group control  mean in group stress 
##              1.706974              1.205009
dat_control = dat %>% filter(group == 'control')
t.test(x=dat_control$mean_acc_logit, mu = 0)
## 
##  One Sample t-test
## 
## data:  dat_control$mean_acc_logit
## t = 9.8233, df = 22, p-value = 1.668e-09
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  1.346600 2.067347
## sample estimates:
## mean of x 
##  1.706974
dat_control = dat %>% filter(group == 'stress')
t.test(x=dat_control$mean_acc_logit, mu = 0)
## 
##  One Sample t-test
## 
## data:  dat_control$mean_acc_logit
## t = 6.3961, df = 22, p-value = 1.953e-06
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.8142949 1.5957230
## sample estimates:
## mean of x 
##  1.205009

Is group -> source accuracy mediated by hippocampal activity for SHs (>CRs)?

Load in hippocampal ROI data

roi = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/pe_sourcehit-cr_zstat1_peak1_5mm_sphere_masked.nii.csv')
roi = roi %>% filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond)) %>% 
  dplyr::select(subid, group, cond, value) %>%  # calc diff score
  spread(key = cond, value=value) %>%
  mutate(diff = sourcehit - CR) %>%
  left_join(dat, by = c('subid', 'group')) %>%
  mutate(diff_orig = diff,
         diff = as.numeric(scale(diff)),
         mean = mean_acc,
         mean_acc_logit = as.numeric(car::logit(mean_acc)),
         mean_acc = as.numeric(scale(car::logit(mean_acc))))
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
roi$subid= factor(roi$subid)
str(roi)
## 'data.frame':    44 obs. of  11 variables:
##  $ subid         : Factor w/ 44 levels "ap100","ap101",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ group         : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ CR            : num  -396 320 107 -519 -416 ...
##  $ sourcehit     : num  379.9 990.6 891.5 90.7 -99.2 ...
##  $ diff          : num  0.967 0.698 0.988 0.542 -0.209 ...
##  $ mean_acc      : num  0.47 1.429 -0.84 0.762 0.993 ...
##  $ sum           : num  89 105 68 113 147 119 125 29 61 20 ...
##  $ count         : num  102 112 97 126 161 138 142 41 94 21 ...
##  $ mean_acc_logit: num  1.924 2.708 0.852 2.162 2.351 ...
##  $ diff_orig     : num  776 671 784 610 317 ...
##  $ mean          : num  0.873 0.938 0.701 0.897 0.913 ...
contrasts(roi$group) = c(1,-1)
with(roi, hist(mean_acc))

with(roi, hist(mean))

roi %>% group_by(group) %>% summarise(mean(mean), mean(mean_acc), n())
## # A tibble: 2 x 4
##     group `mean(mean)` `mean(mean_acc)` `n()`
##    <fctr>        <dbl>            <dbl> <int>
## 1 control    0.8326500        0.2978779    22
## 2  stress    0.7581595       -0.2978779    22

Mediation of group -> assoc acc by posterior hipp BOLD

model.t = lm(mean_acc ~ group, data=roi); summary(model.t) # total effect = 0.30
## 
## Call:
## lm(formula = mean_acc ~ group, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.72781 -0.73339  0.06102  0.56616  1.73891 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept) 1.072e-16  1.455e-01   0.000   1.0000  
## group1      2.979e-01  1.455e-01   2.048   0.0468 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9648 on 42 degrees of freedom
## Multiple R-squared:  0.09079,    Adjusted R-squared:  0.06915 
## F-statistic: 4.194 on 1 and 42 DF,  p-value: 0.04685
#              Estimate Std. Error t value Pr(>|t|)  
# (Intercept) 1.072e-16  1.455e-01   0.000   1.0000  
# group1      2.979e-01  1.455e-01   2.048   0.0468 *
model.m = lm(diff ~ group, data=roi); summary(model.m) # a = 0.35 
## 
## Call:
## lm(formula = diff ~ group, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.84011 -0.56394  0.07552  0.61793  2.94691 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -1.289e-16  1.427e-01   0.000   1.0000  
## group1       3.498e-01  1.427e-01   2.452   0.0185 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9464 on 42 degrees of freedom
## Multiple R-squared:  0.1252, Adjusted R-squared:  0.1044 
## F-statistic: 6.012 on 1 and 42 DF,  p-value: 0.01845
#               Estimate Std. Error t value Pr(>|t|)  
# (Intercept) -1.289e-16  1.427e-01   0.000   1.0000  
# group1       3.498e-01  1.427e-01   2.452   0.0185 *
model.y = lm(mean_acc ~ group + diff, data=roi); summary(model.y)
## 
## Call:
## lm(formula = mean_acc ~ group + diff, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.0503 -0.5369  0.0118  0.4692  1.7126 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)   
## (Intercept) 1.694e-16  1.297e-01   0.000  1.00000   
## group1      1.290e-01  1.386e-01   0.931  0.35745   
## diff        4.827e-01  1.402e-01   3.442  0.00134 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8601 on 41 degrees of freedom
## Multiple R-squared:  0.2946, Adjusted R-squared:  0.2602 
## F-statistic: 8.562 on 2 and 41 DF,  p-value: 0.0007814
#              Estimate Std. Error t value Pr(>|t|)   
# (Intercept) 1.694e-16  1.297e-01   0.000  1.00000   
# group1      1.290e-01  1.386e-01   0.931  0.35745   
# diff        4.827e-01  1.402e-01   3.442  0.00134 **
model.other = lm(mean_acc ~ diff, data=roi); summary(model.other)
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.19405 -0.44648 -0.01872  0.56127  1.82297 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 1.791e-16  1.295e-01   0.000 1.000000    
## diff        5.289e-01  1.310e-01   4.038 0.000224 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8587 on 42 degrees of freedom
## Multiple R-squared:  0.2797, Adjusted R-squared:  0.2626 
## F-statistic: 16.31 on 1 and 42 DF,  p-value: 0.0002237
#              Estimate Std. Error t value Pr(>|t|)    
# (Intercept) 1.791e-16  1.295e-01   0.000 1.000000    
# diff        5.289e-01  1.310e-01   4.038 0.000224 ***
# Multiple R-squared:  0.2797,  Adjusted R-squared:  0.2626 

str(roi)
## 'data.frame':    44 obs. of  11 variables:
##  $ subid         : Factor w/ 44 levels "ap100","ap101",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ group         : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##   ..- attr(*, "contrasts")= num [1:2, 1] 1 -1
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr  "control" "stress"
##   .. .. ..$ : NULL
##  $ CR            : num  -396 320 107 -519 -416 ...
##  $ sourcehit     : num  379.9 990.6 891.5 90.7 -99.2 ...
##  $ diff          : num  0.967 0.698 0.988 0.542 -0.209 ...
##  $ mean_acc      : num  0.47 1.429 -0.84 0.762 0.993 ...
##  $ sum           : num  89 105 68 113 147 119 125 29 61 20 ...
##  $ count         : num  102 112 97 126 161 138 142 41 94 21 ...
##  $ mean_acc_logit: num  1.924 2.708 0.852 2.162 2.351 ...
##  $ diff_orig     : num  776 671 784 610 317 ...
##  $ mean          : num  0.873 0.938 0.701 0.897 0.913 ...
with(roi, plot(mean_acc ~ diff))

plot(model.other)

# does this hold for each group?
with(roi %>% filter(group == 'control'), plot(mean_acc ~ diff))

with(roi %>% filter(group == 'stress'), plot(mean_acc ~ diff))

summary(lm(mean_acc ~ diff, data=roi %>% filter(group == 'control')))
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi %>% filter(group == 
##     "control"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.36817 -0.62660  0.07546  0.37310  1.71925 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)   0.1717     0.2053   0.836    0.413
## diff          0.3608     0.2118   1.703    0.104
## 
## Residual standard error: 0.898 on 20 degrees of freedom
## Multiple R-squared:  0.1266, Adjusted R-squared:  0.08298 
## F-statistic:   2.9 on 1 and 20 DF,  p-value: 0.1041
summary(lm(mean_acc ~ diff, data=roi %>% filter(group == 'stress')))
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi %>% filter(group == 
##     "stress"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.12482 -0.32794 -0.06431  0.65673  1.16147 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -0.09003    0.18811  -0.479  0.63743   
## diff         0.59418    0.18668   3.183  0.00467 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8275 on 20 degrees of freedom
## Multiple R-squared:  0.3362, Adjusted R-squared:  0.303 
## F-statistic: 10.13 on 1 and 20 DF,  p-value: 0.004675
# robust regression since outliers/small sample sizes
library(MASS)
roi %>% filter(group == 'control') %>% summarise(n())
##   n()
## 1  22
summary(rlm(mean_acc ~ diff, data=roi %>% filter(group == 'control')))
## 
## Call: rlm(formula = mean_acc ~ diff, data = roi %>% filter(group == 
##     "control"))
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.36876 -0.59275  0.08731  0.38659  1.73679 
## 
## Coefficients:
##             Value  Std. Error t value
## (Intercept) 0.1416 0.2583     0.5481 
## diff        0.3918 0.2666     1.4697 
## 
## Residual standard error: 0.8403 on 20 degrees of freedom
pt(q = 1.4697, df = 20, lower.tail = FALSE)
## [1] 0.07859963
summary(rlm(mean_acc ~ diff, data=roi %>% filter(group == 'stress')))
## 
## Call: rlm(formula = mean_acc ~ diff, data = roi %>% filter(group == 
##     "stress"))
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.18918 -0.38212 -0.08375  0.59762  1.11121 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept) -0.0398  0.2122    -0.1876
## diff         0.6386  0.2105     3.0331
## 
## Residual standard error: 0.63 on 20 degrees of freedom
pt(q = 3.0331, df = 20, lower.tail = FALSE)
## [1] 0.003283615
# does variability in these measures vary across groups?
roi %>% filter(group == 'control') %>% pull(mean_acc) %>% sd()
## [1] 0.9377136
roi %>% filter(group == 'stress') %>% pull(mean_acc) %>% sd()
## [1] 0.9911605
roi %>% filter(group == 'control') %>% pull(diff) %>% sd()
## [1] 0.9250079
roi %>% filter(group == 'stress') %>% pull(diff) %>% sd()
## [1] 0.9672594
## Bootstrapping Confidence Interval (BCa and Percentile)
boot.med <- function(data, indices){
    data <-data[indices,]   #this does the random resampling of rows

    reg1 <- lm(diff ~ group, data=data)
    reg2 <- lm(mean_acc ~ group + diff, data=data)
    
    a <- coefficients(reg1)["group1"]   #the a path coefficient
    b <- coefficients(reg2)["diff"] #the b path coefficient
    a*b                         #returns the product of a*b
}

medboot<-boot(data=roi, statistic = boot.med, R=5000)   
mean(medboot$t)
## [1] 0.1645124
quantile(medboot$t, c(0.025, 0.975))
##       2.5%      97.5% 
## 0.02385291 0.34857500
# RESULTS:
# > mean(medboot$t)
# [1] 0.1645428
# > quantile(medboot$t, c(0.025, 0.975))
#      2.5%     97.5% 
# 0.0254956 0.3545451 

Plot

p = ggplot(roi, aes(x=diff_orig, y=mean_acc_logit, color=group)) +
  geom_point() +   
  geom_smooth(method=lm, color='black') + 
  geom_point(aes(color=group), size=3, alpha=.8) +
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  xlab('Hippocampal BOLD (a.u.)') +
  ylab('HC associative accuracy\n(logit transformed)') +
    theme(legend.title=element_blank(), legend.position = c(0.2, 0.9),
          plot.margin = unit(c(2, 2, 1, 1), "lines"))
ggsave('~/Experiments/AP/figs/AP_hippXacc.jpeg', dpi=150, width=5.5, height=4.3)

ggsave('~/Dropbox/Stanford/Papers/Dissertation/Figures_Defense/AP_hippXacc.png', dpi=300, width=5.5, height=4.3)

p

Check that this still holds when removing 2 subs w/bad VTC:

subids_rm = c('ap168', 'ap174')

roi = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/pe_sourcehit-cr_zstat1_peak1_5mm_sphere_masked.nii.csv')
roi = roi %>% filter(!subid %in% subids_rm,
                     cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond)) %>% 
  dplyr::select(subid, group, cond, value) %>%  # calc diff score
  spread(key = cond, value=value) %>%
  mutate(diff = sourcehit - CR) %>%
  left_join(dat, by = c('subid', 'group')) %>%
  mutate(diff_orig = diff,
         diff = as.numeric(scale(diff)),
         mean = mean_acc,
         mean_acc = as.numeric(scale(car::logit(mean_acc))))
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
roi$subid= factor(roi$subid)
str(roi)
## 'data.frame':    42 obs. of  11 variables:
##  $ subid         : Factor w/ 42 levels "ap100","ap101",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ group         : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ CR            : num  -396 320 107 -519 -416 ...
##  $ sourcehit     : num  379.9 990.6 891.5 90.7 -99.2 ...
##  $ diff          : num  0.924 0.652 0.945 0.495 -0.263 ...
##  $ mean_acc      : num  0.451 1.433 -0.892 0.75 0.987 ...
##  $ sum           : num  89 105 68 113 147 119 125 29 61 20 ...
##  $ count         : num  102 112 97 126 161 138 142 41 94 21 ...
##  $ mean_acc_logit: num  1.924 2.708 0.852 2.162 2.351 ...
##  $ diff_orig     : num  776 671 784 610 317 ...
##  $ mean          : num  0.873 0.938 0.701 0.897 0.913 ...
contrasts(roi$group) = c(1,-1)
roi %>% group_by(group) %>% summarise(mean(mean), mean(mean_acc), n())
## # A tibble: 2 x 4
##     group `mean(mean)` `mean(mean_acc)` `n()`
##    <fctr>        <dbl>            <dbl> <int>
## 1 control    0.8326500        0.2744294    22
## 2  stress    0.7647046       -0.3018723    20
model.t = lm(mean_acc ~ group, 
             data=roi); summary(model.t) 
## 
## Call:
## lm(formula = mean_acc ~ group, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.80490 -0.75033  0.04542  0.52653  1.78204 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -0.01372    0.14961  -0.092   0.9274  
## group1       0.28815    0.14961   1.926   0.0612 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9685 on 40 degrees of freedom
## Multiple R-squared:  0.08486,    Adjusted R-squared:  0.06198 
## F-statistic: 3.709 on 1 and 40 DF,  p-value: 0.06124
#             Estimate Std. Error t value Pr(>|t|)  
# (Intercept) -0.01372    0.14961  -0.092   0.9274  
# group1       0.28815    0.14961   1.926   0.0612 .
model.m = lm(diff ~ group, 
             data=roi); summary(model.m) 
## 
## Call:
## lm(formula = diff ~ group, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.8664 -0.5615  0.1202  0.5771  2.9000 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -0.01504    0.14821  -0.102   0.9197  
## group1       0.31594    0.14821   2.132   0.0392 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9594 on 40 degrees of freedom
## Multiple R-squared:  0.102,  Adjusted R-squared:  0.07957 
## F-statistic: 4.544 on 1 and 40 DF,  p-value: 0.03922
#             Estimate Std. Error t value Pr(>|t|)  
# (Intercept) -0.01504    0.14821  -0.102   0.9197  
# group1       0.31594    0.14821   2.132   0.0392 *
model.y = lm(mean_acc ~ group + diff, 
             data=roi); summary(model.y)
## 
## Call:
## lm(formula = mean_acc ~ group + diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.08607 -0.49224  0.01576  0.38171  1.75627 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -0.006673   0.134229  -0.050  0.96061   
## group1       0.140123   0.141631   0.989  0.32859   
## diff         0.468537   0.143185   3.272  0.00224 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8688 on 39 degrees of freedom
## Multiple R-squared:  0.282,  Adjusted R-squared:  0.2452 
## F-statistic: 7.659 on 2 and 39 DF,  p-value: 0.001565
#              Estimate Std. Error t value Pr(>|t|)   
# (Intercept) -0.006673   0.134229  -0.050  0.96061   
# group1       0.140123   0.141631   0.989  0.32859   
# diff         0.468537   0.143185   3.272  0.00224 **
model.other = lm(mean_acc ~ diff, 
                 data=roi); summary(model.other)
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.24505 -0.45864 -0.00737  0.52330  1.87362 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.593e-17  1.340e-01   0.000 1.000000    
## diff         5.138e-01  1.356e-01   3.788 0.000501 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8686 on 40 degrees of freedom
## Multiple R-squared:  0.264,  Adjusted R-squared:  0.2456 
## F-statistic: 14.35 on 1 and 40 DF,  p-value: 0.0005012
#              Estimate Std. Error t value Pr(>|t|)    
# (Intercept) -2.593e-17  1.340e-01   0.000 1.000000    
# diff         5.138e-01  1.356e-01   3.788 0.000501 ***
# Multiple R-squared:  0.264,   Adjusted R-squared:  0.2456 
 
str(roi)
## 'data.frame':    42 obs. of  11 variables:
##  $ subid         : Factor w/ 42 levels "ap100","ap101",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ group         : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##   ..- attr(*, "contrasts")= num [1:2, 1] 1 -1
##   .. ..- attr(*, "dimnames")=List of 2
##   .. .. ..$ : chr  "control" "stress"
##   .. .. ..$ : NULL
##  $ CR            : num  -396 320 107 -519 -416 ...
##  $ sourcehit     : num  379.9 990.6 891.5 90.7 -99.2 ...
##  $ diff          : num  0.924 0.652 0.945 0.495 -0.263 ...
##  $ mean_acc      : num  0.451 1.433 -0.892 0.75 0.987 ...
##  $ sum           : num  89 105 68 113 147 119 125 29 61 20 ...
##  $ count         : num  102 112 97 126 161 138 142 41 94 21 ...
##  $ mean_acc_logit: num  1.924 2.708 0.852 2.162 2.351 ...
##  $ diff_orig     : num  776 671 784 610 317 ...
##  $ mean          : num  0.873 0.938 0.701 0.897 0.913 ...
with(roi, plot(mean_acc ~ diff))

# does this hold for each group?
with(roi %>% filter(group == 'control'), plot(mean_acc ~ diff))

with(roi %>% filter(group == 'stress',
                    !subid %in% subids_rm), plot(mean_acc ~ diff))

summary(lm(mean_acc ~ diff, data=roi %>% filter(group == 'control')))
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi %>% filter(group == 
##     "control"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.40211 -0.64214  0.07733  0.38236  1.76189 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)   0.1642     0.2066   0.795    0.436
## diff          0.3663     0.2151   1.703    0.104
## 
## Residual standard error: 0.9202 on 20 degrees of freedom
## Multiple R-squared:  0.1266, Adjusted R-squared:  0.08298 
## F-statistic:   2.9 on 1 and 20 DF,  p-value: 0.1041
summary(lm(mean_acc ~ diff, data=roi %>% filter(group == 'stress')))
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi %>% filter(group == 
##     "stress"))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.14672 -0.31308 -0.01764  0.47936  1.21700 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept)  -0.1133     0.1940  -0.584  0.56638   
## diff          0.5696     0.1907   2.987  0.00791 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8206 on 18 degrees of freedom
## Multiple R-squared:  0.3314, Adjusted R-squared:  0.2942 
## F-statistic:  8.92 on 1 and 18 DF,  p-value: 0.007912
# robust regression since outliers/small sample sizes
library(MASS)
summary(rlm(mean_acc ~ diff, data=roi %>% filter(group == 'control')))
## 
## Call: rlm(formula = mean_acc ~ diff, data = roi %>% filter(group == 
##     "control"))
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.40271 -0.60746  0.08947  0.39618  1.77987 
## 
## Coefficients:
##             Value  Std. Error t value
## (Intercept) 0.1350 0.2600     0.5194 
## diff        0.3978 0.2707     1.4697 
## 
## Residual standard error: 0.8611 on 20 degrees of freedom
pt(q = 1.4697, df = 20, lower.tail = FALSE)
## [1] 0.07859963
summary(rlm(mean_acc ~ diff, data=roi %>% filter(group == 'stress')))
## 
## Call: rlm(formula = mean_acc ~ diff, data = roi %>% filter(group == 
##     "stress"))
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.20935 -0.35669 -0.08597  0.46470  1.15984 
## 
## Coefficients:
##             Value   Std. Error t value
## (Intercept) -0.0629  0.1898    -0.3315
## diff         0.6148  0.1865     3.2967
## 
## Residual standard error: 0.5525 on 18 degrees of freedom
pt(q = 3.2967, df = 20, lower.tail = FALSE)
## [1] 0.001801785
## Bootstrapping Confidence Interval (BCa and Percentile)
boot.med <- function(data, indices){
    data <-data[indices,]   #this does the random resampling of rows

    reg1 <- lm(diff ~ group, data=data)
    reg2 <- lm(mean_acc ~ group + diff, data=data)
    
    a <- coefficients(reg1)["group1"]   #the a path coefficient
    b <- coefficients(reg2)["diff"] #the b path coefficient
    a*b                         #returns the product of a*b
}

medboot<-boot(data=roi, 
              statistic = boot.med, R=5000)
mean(medboot$t)
## [1] 0.1407147
quantile(medboot$t, c(0.025, 0.975))
##       2.5%      97.5% 
## 0.00384396 0.30884270
# RESULTS:
# > mean(medboot$t)
# [1] 0.1415879
# > quantile(medboot$t, c(0.025, 0.975))
#          2.5%         97.5% 
# -0.0001349303  0.3141738951

Is hipp effect on source accuracy mediated by VTC reinstatement?

vtc = read.csv('/Volumes/group/awagner/sgagnon/AP/results/sourcehit_avglogit_vtc.csv')
vtc = vtc %>% mutate(mean_logit = mean) %>% dplyr::select(-mean)

roi = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/pe_sourcehit-cr_zstat1_peak1_5mm_sphere_masked.nii.csv')
roi = roi %>% filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond)) %>% 
  dplyr::select(subid, group, cond, value) %>%  # calc diff score
  spread(key = cond, value=value) %>%
  mutate(diff = sourcehit - CR) %>%
  right_join(vtc, by = c('subid', 'group')) %>%
  left_join(dat, by = c('subid', 'group')) %>%
  mutate(diff_orig = diff,
         diff = as.numeric(scale(diff)),
         logit_orig = mean_logit,
         mean_logit = scale(mean_logit),
         mean_acc_logit = as.numeric(car::logit(mean_acc)),
         mean_acc = as.numeric(scale(car::logit(mean_acc))))
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector
dim(roi)
## [1] 42 13
str(roi)
## 'data.frame':    42 obs. of  13 variables:
##  $ subid         : chr  "ap100" "ap101" "ap102" "ap103" ...
##  $ group         : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ CR            : num  -396 320 107 -519 -416 ...
##  $ sourcehit     : num  379.9 990.6 891.5 90.7 -99.2 ...
##  $ diff          : num  0.924 0.652 0.945 0.495 -0.263 ...
##  $ X             : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ mean_logit    : num [1:42, 1] 0.3483 -0.2448 0.7178 -0.8012 -0.0116 ...
##   ..- attr(*, "scaled:center")= num 0.854
##   ..- attr(*, "scaled:scale")= num 0.66
##  $ mean_acc      : num  0.451 1.433 -0.892 0.75 0.987 ...
##  $ sum           : num  89 105 68 113 147 119 125 29 61 20 ...
##  $ count         : num  102 112 97 126 161 138 142 41 94 21 ...
##  $ mean_acc_logit: num  1.924 2.708 0.852 2.162 2.351 ...
##  $ diff_orig     : num  776 671 784 610 317 ...
##  $ logit_orig    : num  1.084 0.693 1.328 0.326 0.847 ...
roi %>% group_by(group) %>% summarise(n()) # n=22, 20
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    20
contrasts(roi$group) = c(1,-1)

model.t = lm(mean_acc ~ diff, data=roi); summary(model.t) 
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.24505 -0.45864 -0.00737  0.52330  1.87362 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.593e-17  1.340e-01   0.000 1.000000    
## diff         5.138e-01  1.356e-01   3.788 0.000501 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8686 on 40 degrees of freedom
## Multiple R-squared:  0.264,  Adjusted R-squared:  0.2456 
## F-statistic: 14.35 on 1 and 40 DF,  p-value: 0.0005012
#               Estimate Std. Error t value Pr(>|t|)    
# (Intercept) -2.593e-17  1.340e-01   0.000 1.000000    
# diff         5.138e-01  1.356e-01   3.788 0.000501 ***
model.m = lm(mean_logit ~ diff, data=roi); summary(model.m)
## 
## Call:
## lm(formula = mean_logit ~ diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.27791 -0.36144  0.08478  0.46973  1.73971 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 4.251e-17  1.336e-01   0.000 1.000000    
## diff        5.187e-01  1.352e-01   3.837 0.000433 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8656 on 40 degrees of freedom
## Multiple R-squared:  0.2691, Adjusted R-squared:  0.2508 
## F-statistic: 14.72 on 1 and 40 DF,  p-value: 0.0004327
#              Estimate Std. Error t value Pr(>|t|)    
# (Intercept) 4.251e-17  1.336e-01   0.000 1.000000    
# diff        5.187e-01  1.352e-01   3.837 0.000433 ***
model.y = lm(mean_acc ~ mean_logit + diff, data=roi); summary(model.y)
## 
## Call:
## lm(formula = mean_acc ~ mean_logit + diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.23819 -0.47077  0.00205  0.53071  1.87638 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -2.756e-17  1.356e-01   0.000  1.00000   
## mean_logit   3.837e-02  1.606e-01   0.239  0.81240   
## diff         4.939e-01  1.606e-01   3.076  0.00383 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.879 on 39 degrees of freedom
## Multiple R-squared:  0.265,  Adjusted R-squared:  0.2274 
## F-statistic: 7.032 on 2 and 39 DF,  p-value: 0.002466
#               Estimate Std. Error t value Pr(>|t|)   
# (Intercept) -2.756e-17  1.356e-01   0.000  1.00000   
# mean_logit   3.837e-02  1.606e-01   0.239  0.81240   
# diff         4.939e-01  1.606e-01   3.076  0.00383 **
model.other = lm(mean_acc ~ mean_logit, data=roi); summary(model.other) #marginal
## 
## Call:
## lm(formula = mean_acc ~ mean_logit, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.0953 -0.7960 -0.1424  0.7132  2.0233 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -3.227e-17  1.493e-01   0.000   1.0000  
## mean_logit   2.946e-01  1.511e-01   1.949   0.0583 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9675 on 40 degrees of freedom
## Multiple R-squared:  0.08676,    Adjusted R-squared:  0.06393 
## F-statistic:   3.8 on 1 and 40 DF,  p-value: 0.05829
# (Intercept) -3.227e-17  1.493e-01   0.000   1.0000  
# mean_logit   2.946e-01  1.511e-01   1.949   0.0583 .
# Multiple R-squared:  0.08676, Adjusted R-squared:  0.06393 

# any effect of group on reinstatement, when controlling for hipp?
summary(lm(mean_logit ~ diff + group, data=roi))
## 
## Call:
## lm(formula = mean_logit ~ diff + group, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.26845 -0.36500  0.07507  0.45777  1.73456 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.0005613  0.1354209  -0.004 0.996714    
## diff         0.5149071  0.1444561   3.564 0.000982 ***
## group1       0.0117880  0.1428881   0.082 0.934673    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8765 on 39 degrees of freedom
## Multiple R-squared:  0.2692, Adjusted R-squared:  0.2317 
## F-statistic: 7.183 on 2 and 39 DF,  p-value: 0.002209
## Bootstrapping Confidence Interval (BCa and Percentile)
boot.med <- function(data, indices){
    data <-data[indices,]   #this does the random resampling of rows

    reg1 <- lm(mean_logit ~ diff, data=data)
    reg2 <- lm(mean_acc ~ mean_logit + diff, data=data)
    
    a <- coefficients(reg1)["diff"] #the a path coefficient
    b <- coefficients(reg2)["mean_logit"]   #the b path coefficient
    a*b                         #returns the product of a*b
}

medboot<-boot(data=roi, statistic = boot.med, R=5000)   
mean(medboot$t)
## [1] 0.021213
quantile(medboot$t, c(0.025, 0.975))
##       2.5%      97.5% 
## -0.1464613  0.1902283
# RESULTS:
# > mean(medboot$t)
# [1] 0.0239775
# > quantile(medboot$t, c(0.025, 0.975))
#       2.5%      97.5% 
# -0.1401416  0.1945644 

Plots

ggplot(roi, aes(x=logit_orig, y=mean_acc_logit, color=group)) +
  geom_point() +   
  geom_smooth(method=lm, color='black') + 
  geom_point(aes(color=group), size=3, alpha=.8) +
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  xlab('Reinstatement strength (logits)') +
  ylab('HC associative accuracy\n(logit transformed)') +
    theme(legend.title=element_blank(), legend.position = c(0.2, 0.9),
          plot.margin = unit(c(2, 2, 1, 1), "lines"))

ggsave('~/Experiments/AP/figs/AP_logitXacc.jpeg', dpi=150, width=5.5, height=4.3)
ggsave('~/Dropbox/Stanford/Papers/Dissertation/Figures_Defense/AP_logitXacc.png', dpi=300, width=5.5, height=4.3)

ggplot(roi, aes(x=diff, y=logit_orig, color=group)) +
  geom_point() +   
  geom_smooth(method=lm, color='black') + 
  geom_point(aes(color=group), size=3, alpha=.8) +
  scale_color_manual(values=c('dodgerblue', 'orange')) +
  xlab('Hippocampal BOLD (a.u.)') +
  ylab('Reinstatement strength (logits)') +
    theme(legend.title=element_blank(), legend.position = c(0.2, 0.9),
          plot.margin = unit(c(2, 2, 1, 1), "lines"))

ggsave('~/Experiments/AP/figs/AP_logitXhipp.jpeg', dpi=150, width=5.5, height=4.3)
ggsave('~/Dropbox/Stanford/Papers/Dissertation/Figures_Defense/AP_logitXhipp.png', dpi=300, width=5.5, height=4.8)
roi = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/pe_sourcehit-cr_zstat1_peak1_5mm_sphere_masked.nii.csv')
roi = roi %>% filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond)) %>% 
  dplyr::select(subid, group, cond, value) %>%  # calc diff score
  spread(key = cond, value=value) %>%
  mutate(diff = sourcehit - CR) %>%
  right_join(slopes_ccn_rt, by = c('subid')) %>%
  left_join(dat, by = c('subid', 'group')) %>%
  mutate(diff_orig = diff,
         diff = as.numeric(scale(diff)),
         slope_orig = coef,
         scaled_coef = as.numeric(scale(coef)),
         mean_acc = as.numeric(scale(car::logit(mean_acc))))
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector
dim(roi)
## [1] 42 13
str(roi)
## 'data.frame':    42 obs. of  13 variables:
##  $ subid         : chr  "ap100" "ap101" "ap102" "ap103" ...
##  $ group         : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ CR            : num  -396 320 107 -519 -416 ...
##  $ sourcehit     : num  379.9 990.6 891.5 90.7 -99.2 ...
##  $ diff          : num  0.924 0.652 0.945 0.495 -0.263 ...
##  $ coef          : num  0.185 0.205 0.146 0.164 0.175 ...
##  $ mean_acc      : num  0.451 1.433 -0.892 0.75 0.987 ...
##  $ sum           : num  89 105 68 113 147 119 125 29 61 20 ...
##  $ count         : num  102 112 97 126 161 138 142 41 94 21 ...
##  $ mean_acc_logit: num  1.924 2.708 0.852 2.162 2.351 ...
##  $ diff_orig     : num  776 671 784 610 317 ...
##  $ slope_orig    : num  0.185 0.205 0.146 0.164 0.175 ...
##  $ scaled_coef   : num  0.365 0.488 0.132 0.241 0.308 ...
contrasts(roi$group) = c(1,-1)

summary(lm(scaled_coef ~ group, data=roi))
## 
## Call:
## lm(formula = scaled_coef ~ group, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.58283 -0.30618 -0.07339  0.46506  2.56691 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -0.01883    0.14336  -0.131  0.89615   
## group1       0.39545    0.14336   2.759  0.00871 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.928 on 40 degrees of freedom
## Multiple R-squared:  0.1598, Adjusted R-squared:  0.1388 
## F-statistic:  7.61 on 1 and 40 DF,  p-value: 0.008712
summary(lm(mean_acc ~ scaled_coef + group, data=roi))
## 
## Call:
## lm(formula = mean_acc ~ scaled_coef + group, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.47825 -0.64423 -0.07226  0.65890  1.80703 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -0.007718   0.144308  -0.053   0.9576  
## scaled_coef  0.318828   0.159131   2.004   0.0521 .
## group1       0.162070   0.157403   1.030   0.3095  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.934 on 39 degrees of freedom
## Multiple R-squared:  0.1703, Adjusted R-squared:  0.1277 
## F-statistic: 4.002 on 2 and 39 DF,  p-value: 0.02626
summary(lm(mean_acc ~ scaled_coef + group + diff, data=roi))
## 
## Call:
## lm(formula = mean_acc ~ scaled_coef + group + diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.77166 -0.48848 -0.08121  0.42874  1.78043 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -0.001192   0.128654  -0.009  0.99265   
## scaled_coef  0.300171   0.141963   2.114  0.04110 * 
## group1       0.025041   0.146227   0.171  0.86494   
## diff         0.457074   0.137317   3.329  0.00195 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8326 on 38 degrees of freedom
## Multiple R-squared:  0.3576, Adjusted R-squared:  0.3069 
## F-statistic:  7.05 on 3 and 38 DF,  p-value: 0.0006981

Is hipp effect on source accuracy mediated by infparietal reinstatement?

Note that this analysis is excluding 2 subjs w/poor VTC localizer classification.

vtc = read.csv('/Volumes/group/awagner/sgagnon/AP/results/sourcehit_avglogit_infparietal.csv')
vtc = vtc %>% mutate(mean_logit = mean) %>% dplyr::select(-mean)
dim(vtc)
## [1] 42  4
vtc %>% group_by(subid, group) %>% summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    20
roi = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/pe_sourcehit-cr_zstat1_peak1_5mm_sphere_masked.nii.csv')
roi = roi %>% filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond)) %>% 
  dplyr::select(subid, group, cond, value) %>%  # calc diff score
  spread(key = cond, value=value) %>%
  mutate(diff = sourcehit - CR) %>%
  right_join(vtc, by = c('subid', 'group')) %>%
  left_join(dat, by = c('subid', 'group')) %>%
  mutate(diff_orig = diff,
         diff = scale(diff),
         mean_logit = scale(mean_logit),
          mean_acc = as.numeric(scale(car::logit(mean_acc))))
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector
dim(roi)
## [1] 42 12
str(roi)
## 'data.frame':    42 obs. of  12 variables:
##  $ subid         : chr  "ap100" "ap101" "ap102" "ap103" ...
##  $ group         : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ CR            : num  -396 320 107 -519 -416 ...
##  $ sourcehit     : num  379.9 990.6 891.5 90.7 -99.2 ...
##  $ diff          : num [1:42, 1] 0.924 0.652 0.945 0.495 -0.263 ...
##   ..- attr(*, "scaled:center")= num 418
##   ..- attr(*, "scaled:scale")= num 387
##  $ X             : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ mean_logit    : num [1:42, 1] -0.0671 0.2441 0.8726 -1.4194 -0.1556 ...
##   ..- attr(*, "scaled:center")= num 0.274
##   ..- attr(*, "scaled:scale")= num 0.709
##  $ mean_acc      : num  0.451 1.433 -0.892 0.75 0.987 ...
##  $ sum           : num  89 105 68 113 147 119 125 29 61 20 ...
##  $ count         : num  102 112 97 126 161 138 142 41 94 21 ...
##  $ mean_acc_logit: num  1.924 2.708 0.852 2.162 2.351 ...
##  $ diff_orig     : num  776 671 784 610 317 ...
contrasts(roi$group) = c(1,-1)

model.t = lm(mean_acc ~ diff, data=roi); summary(model.t) 
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.24505 -0.45864 -0.00737  0.52330  1.87362 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.593e-17  1.340e-01   0.000 1.000000    
## diff         5.138e-01  1.356e-01   3.788 0.000501 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8686 on 40 degrees of freedom
## Multiple R-squared:  0.264,  Adjusted R-squared:  0.2456 
## F-statistic: 14.35 on 1 and 40 DF,  p-value: 0.0005012
model.m = lm(mean_logit ~ diff, data=roi); summary(model.m)
## 
## Call:
## lm(formula = mean_logit ~ diff, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.5604 -0.6458 -0.1284  0.5507  2.2856 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -2.630e-17  1.497e-01    0.00   1.0000  
## diff         2.849e-01  1.516e-01    1.88   0.0674 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9705 on 40 degrees of freedom
## Multiple R-squared:  0.08119,    Adjusted R-squared:  0.05821 
## F-statistic: 3.534 on 1 and 40 DF,  p-value: 0.06741
model.y = lm(mean_acc ~ mean_logit + diff, data=roi); summary(model.y)
## 
## Call:
## lm(formula = mean_acc ~ mean_logit + diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.23418 -0.46397 -0.00129  0.51094  1.86800 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -2.431e-17  1.354e-01   0.000  1.00000   
## mean_logit   6.171e-02  1.430e-01   0.432  0.66842   
## diff         4.962e-01  1.430e-01   3.471  0.00128 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8775 on 39 degrees of freedom
## Multiple R-squared:  0.2675, Adjusted R-squared:  0.2299 
## F-statistic:  7.12 on 2 and 39 DF,  p-value: 0.002312
model.other = lm(mean_acc ~ mean_logit, data=roi); summary(model.other)
## 
## Call:
## lm(formula = mean_acc ~ mean_logit, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.0866 -0.7677 -0.1106  0.7970  2.0174 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.278e-17  1.530e-01   0.000    1.000
## mean_logit   2.031e-01  1.548e-01   1.312    0.197
## 
## Residual standard error: 0.9913 on 40 degrees of freedom
## Multiple R-squared:  0.04125,    Adjusted R-squared:  0.01728 
## F-statistic: 1.721 on 1 and 40 DF,  p-value: 0.1971
## Bootstrapping Confidence Interval (BCa and Percentile)
boot.med <- function(data, indices){
    data <-data[indices,]   #this does the random resampling of rows

    reg1 <- lm(mean_logit ~ diff, data=data)
    reg2 <- lm(mean_acc ~ mean_logit + diff, data=data)
    
    a <- coefficients(reg1)["diff"] #the a path coefficient
    b <- coefficients(reg2)["mean_logit"]   #the b path coefficient
    a*b                         #returns the product of a*b
}

medboot<-boot(data=roi, statistic = boot.med, R=5000)   
mean(medboot$t)
## [1] 0.01262749
quantile(medboot$t, c(0.025, 0.975))
##        2.5%       97.5% 
## -0.08775011  0.10527620

5b) Predictors of LC accuracy

dat = dtest %>% 
  filter(subj_status == 'old', 
         reps > 0,
         conf == 'Lo') %>%
  group_by(subid, group) %>%
  summarise(mean_acc = mean(acc_num), count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), fill = list(mean_acc=0,
                                              count=0))
dim(dat) # missing 104, with no LC responses
## [1] 46  4
dat %>% filter(count < 6) 
## # A tibble: 3 x 4
##    subid   group  mean_acc count
##   <fctr>  <fctr>     <dbl> <dbl>
## 1  ap116 control 0.6666667     3
## 2  ap160  stress 1.0000000     1
## 3  ap169  stress 0.0000000     2
rm_subids = dat %>% filter(count < 6) %>% pull(subid) %>% unique()
rm_subids
## [1] ap116 ap160 ap169
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
dat = dat %>% filter(!subid %in% rm_subids)

dat %>% group_by(subid, group) %>% summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    21
## 2  stress    22
hist(dat$mean_acc)

dat = dat%>% mutate(mean_acc_logit = car::logit(mean_acc))
hist(dat$mean_acc_logit)

bartlett.test(mean_acc_logit ~ group, data=dat)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean_acc_logit by group
## Bartlett's K-squared = 3.1647, df = 1, p-value = 0.07525
t.test(mean_acc_logit ~ group, data=dat, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  mean_acc_logit by group
## t = 2.5569, df = 41, p-value = 0.01436
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.04654901 0.39641939
## sample estimates:
## mean in group control  mean in group stress 
##            0.28273408            0.06124988
dat_control = dat %>% filter(group == 'control')
t.test(x=dat_control$mean_acc_logit, mu = 0)
## 
##  One Sample t-test
## 
## data:  dat_control$mean_acc_logit
## t = 3.8644, df = 20, p-value = 0.0009659
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.1301165 0.4353517
## sample estimates:
## mean of x 
## 0.2827341
dat_control = dat %>% filter(group == 'stress')
t.test(x=dat_control$mean_acc_logit, mu = 0)
## 
##  One Sample t-test
## 
## data:  dat_control$mean_acc_logit
## t = 1.2805, df = 21, p-value = 0.2143
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.03822232  0.16072209
## sample estimates:
##  mean of x 
## 0.06124988
dat
## # A tibble: 43 x 5
##     subid   group  mean_acc count mean_acc_logit
##    <fctr>  <fctr>     <dbl> <dbl>          <dbl>
##  1  ap100 control 0.4400000    25    -0.24116206
##  2  ap101 control 0.6666667    21     0.69314718
##  3  ap102 control 0.4285714    63    -0.28768207
##  4  ap103 control 0.5909091    22     0.36772478
##  5  ap105 control 0.7058824    17     0.87546874
##  6  ap106 control 0.6400000    75     0.57536414
##  7  ap107 control 0.6470588    17     0.60613580
##  8  ap108 control 0.6086957    69     0.44183275
##  9  ap109 control 0.5000000    46     0.00000000
## 10  ap110 control 0.5140187   107     0.05608947
## # ... with 33 more rows

Does hipp track LC accuracy?

roi = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/pe_sourcehit-cr_zstat1_peak1_5mm_sphere_masked.nii.csv')
roi %>% group_by(subid, group) %>% summarise(n()) %>%  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    22
roi = roi %>% filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond)) %>% 
  dplyr::select(subid, group, cond, value) %>%  # calc diff score
  spread(key = cond, value=value) %>%
  mutate(diff = sourcehit - CR) %>%
  inner_join(dat, by = c('subid', 'group')) %>%
  mutate(diff_orig = diff,
         diff = scale(diff),
          mean_acc = as.numeric(scale(car::logit(mean_acc))))
## Warning in inner_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
dim(roi)
## [1] 40  9
str(roi)
## 'data.frame':    40 obs. of  9 variables:
##  $ subid         : chr  "ap100" "ap101" "ap102" "ap103" ...
##  $ group         : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ CR            : num  -396 320 107 -519 706 ...
##  $ sourcehit     : num  379.9 990.6 891.5 90.7 1278.5 ...
##  $ diff          : num [1:40, 1] 0.916 0.654 0.937 0.502 0.409 ...
##   ..- attr(*, "scaled:center")= num 408
##   ..- attr(*, "scaled:scale")= num 401
##  $ mean_acc      : num  -1.309 1.747 -1.461 0.682 2.343 ...
##  $ count         : num  25 21 63 22 17 17 69 46 107 68 ...
##  $ mean_acc_logit: num  -0.241 0.693 -0.288 0.368 0.875 ...
##  $ diff_orig     : num  776 671 784 610 573 ...
roi %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    20
## 2  stress    20
contrasts(roi$group) = c(1,-1)
model.t = lm(mean_acc ~ diff, data=roi); summary(model.t) 
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.81880 -0.58962  0.03591  0.57668  2.23727 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) 9.070e-18  1.547e-01   0.000    1.000
## diff        2.583e-01  1.567e-01   1.648    0.108
## 
## Residual standard error: 0.9787 on 38 degrees of freedom
## Multiple R-squared:  0.06674,    Adjusted R-squared:  0.04218 
## F-statistic: 2.717 on 1 and 38 DF,  p-value: 0.1075
ggplot(roi, aes(x=diff_orig, y=mean_acc)) +
  geom_point() +   
  geom_smooth(method=lm) +
  xlab('Hippocampus SH > CR') +
  ylab('Low conf source accuracy (logit)')

6) Effects of stress on frontoparietal networks (and interactions by run type)

basedir = '/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/'
# dt = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/mvpa/notebooks/ap_behav.csv') #already read in
# head(dt)
counts = dt %>%
  filter(mem_conditions %in% c('CR', 'sourcehit')) %>%
  group_by(subid, mem_conditions) %>%
  summarise(n=n()) %>%
  ungroup() %>%
  complete(subid, mem_conditions, fill = list(n=0)) 
  # filter(mem_conditions %in% c('sourcehit', 'CR'))
# length(unique(dt$mem_conditions)) * length(unique(dt$subid))

sub_remove = counts %>% 
  filter(mem_conditions %in% c('sourcehit', 'CR'), 
         n <= 5) %>% 
  pull(subid); sub_remove
## [1] ap151 ap156
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
sub_remove
## [1] ap151 ap156
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
dt %>%
  filter(mem_conditions %in% c('CR', 'sourcehit')) %>%
  mutate(mem_conditions = factor(mem_conditions)) %>%
  group_by(subid, shockCond, mem_conditions) %>%
  summarise(n=n()) %>%
  ungroup() %>%
  complete(subid, shockCond, mem_conditions, fill = list(n=0)) %>%
  filter(n < 6)
## # A tibble: 8 x 4
##    subid shockCond mem_conditions     n
##   <fctr>    <fctr>         <fctr> <dbl>
## 1  ap121    threat             CR     1
## 2  ap151      safe      sourcehit     2
## 3  ap151    threat      sourcehit     1
## 4  ap156      safe      sourcehit     0
## 5  ap156    threat      sourcehit     5
## 6  ap158      safe      sourcehit     5
## 7  ap164      safe             CR     5
## 8  ap173    threat      sourcehit     1
dt %>%
  filter(mem_conditions %in% c('CR', 'sourcehit')) %>%
  mutate(mem_conditions = factor(mem_conditions)) %>%
  group_by(subid, group, shockCond, mem_conditions) %>%
  summarise(n=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group),
           shockCond, mem_conditions, fill = list(n=0)) %>%
  group_by(subid, group) %>% summarise(min = min(n)) %>%
  filter(min > 5) %>%
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##          group `n()`
##         <fctr> <int>
## 1 control-fmri    21
## 2  stress-fmri    20
# and ap106 has too much motion, so n = 20 control

6a) CCN

d2 = read.csv(paste(basedir,'pe_frontoparietal.csv', sep=''))
data = d2 %>%
  filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond)) %>% 
  filter(!(subid %in% sub_remove))

data %>% group_by(subid, group) %>% summarise(n()) %>% 
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    22
contrasts(data$group) = c(1, -1); contrasts(data$group)
##         [,1]
## control    1
## stress    -1
data$cond = factor(data$cond)
contrasts(data$cond) = c(-1,1); contrasts(data$cond)
##           [,1]
## CR          -1
## sourcehit    1
contrasts(data$hemi) = c(1,-1); contrasts(data$hemi)
##    [,1]
## lh    1
## rh   -1
summary(lmer(value ~ group * cond + (1|subid), 
             data=data %>% filter(hemi == 'lh')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond + (1 | subid)
##    Data: data %>% filter(hemi == "lh")
## 
## REML criterion at convergence: 1328.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.67637 -0.56419 -0.06267  0.41560  2.39691 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 187800   433.4   
##  Residual             210164   458.4   
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##              Estimate Std. Error     df t value Pr(>|t|)    
## (Intercept)    242.70      81.59  42.00   2.975  0.00484 ** 
## group1         -14.20      81.59  42.00  -0.174  0.86268    
## cond1          599.74      48.87  40.43  12.272 3.11e-15 ***
## group1:cond1    76.59      48.87  40.43   1.567  0.12488    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1
## group1      0.000              
## cond1       0.000  0.000       
## group1:cnd1 0.000  0.000  0.000
summary(lmer(value ~ group * cond * hemi + (1 + cond + hemi|subid), data=data)) # including cond RE not enough obs
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond * hemi + (1 + cond + hemi | subid)
##    Data: data
## 
## REML criterion at convergence: 2577.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.09901 -0.45367  0.03082  0.45005  2.04655 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr       
##  subid    (Intercept) 218481   467.4               
##           cond1        53497   231.3    -0.21      
##           hemi1        11592   107.7     0.23  0.89
##  Residual              79029   281.1               
## Number of obs: 176, groups:  subid, 44
## 
## Fixed effects:
##                    Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)          -5.012     73.583  42.000  -0.068    0.946    
## group1              -10.210     73.583  42.000  -0.139    0.890    
## cond1               382.772     40.803  42.000   9.381 7.29e-12 ***
## hemi1               247.711     26.692  42.000   9.280 9.94e-12 ***
## group1:cond1         54.942     40.803  42.000   1.347    0.185    
## group1:hemi1         -3.988     26.692  42.000  -0.149    0.882    
## cond1:hemi1         216.966     21.190  41.110  10.239 7.08e-13 ***
## group1:cond1:hemi1   21.643     21.190  41.110   1.021    0.313    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1  hemi1  grp1:c1 grp1:h1 cnd1:1
## group1       0.000                                            
## cond1       -0.168  0.000                                     
## hemi1        0.135  0.000  0.462                              
## group1:cnd1  0.000 -0.168  0.000  0.000                       
## group1:hem1  0.000  0.135  0.000  0.000  0.462                
## cond1:hemi1  0.000  0.000  0.000  0.000  0.000   0.000        
## grp1:cnd1:1  0.000  0.000  0.000  0.000  0.000   0.000   0.000

6b) DAN

d2 = read.csv(paste(basedir,'pe_dorsalattn.csv', sep=''))
data = d2 %>%
  filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond)) %>% 
  filter(!(subid %in% sub_remove))

data %>% group_by(subid, group) %>% summarise(n()) %>% 
  group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    22
contrasts(data$group) = c(1, -1); contrasts(data$group)
##         [,1]
## control    1
## stress    -1
data$cond = factor(data$cond)
contrasts(data$cond) = c(-1,1); contrasts(data$cond)
##           [,1]
## CR          -1
## sourcehit    1
contrasts(data$hemi) = c(1,-1); contrasts(data$hemi)
##    [,1]
## lh    1
## rh   -1
summary(lmer(value ~ group * cond + (1|subid), 
             data=data %>% filter(hemi == 'lh')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond + (1 | subid)
##    Data: data %>% filter(hemi == "lh")
## 
## REML criterion at convergence: 1340.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.3926 -0.4691  0.0128  0.5090  2.2320 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 346686   588.8   
##  Residual             185004   430.1   
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##              Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)   1040.58      99.91   42.00  10.415 3.28e-13 ***
## group1         176.51      99.91   42.00   1.767 0.084543 .  
## cond1          194.05      45.85   41.08   4.232 0.000127 ***
## group1:cond1    59.92      45.85   41.08   1.307 0.198526    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1
## group1      0.000              
## cond1       0.000  0.000       
## group1:cnd1 0.000  0.000  0.000
summary(lmer(value ~ group * cond * hemi + (1 + cond + hemi|subid), data=data)) # including cond RE not enough obs
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond * hemi + (1 + cond + hemi | subid)
##    Data: data
## 
## REML criterion at convergence: 2551.1
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.43574 -0.37814  0.00211  0.43352  1.32768 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr     
##  subid    (Intercept) 330476   574.9             
##           cond1        73038   270.3    0.04     
##           hemi1        32412   180.0    0.32 0.15
##  Residual              18949   137.7             
## Number of obs: 176, groups:  subid, 44
## 
## Fixed effects:
##                    Estimate Std. Error     df t value Pr(>|t|)    
## (Intercept)          790.81      87.28  42.00   9.060 1.96e-11 ***
## group1               121.07      87.28  42.00   1.387  0.17274    
## cond1                132.16      42.04  42.00   3.143  0.00306 ** 
## hemi1                249.76      29.06  42.00   8.596 8.39e-11 ***
## group1:cond1          45.04      42.04  42.00   1.071  0.29014    
## group1:hemi1          55.44      29.06  42.00   1.908  0.06324 .  
## cond1:hemi1           61.89      10.38  42.03   5.965 4.45e-07 ***
## group1:cond1:hemi1    14.88      10.38  42.03   1.434  0.15896    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1 hemi1 grp1:c1 grp1:h1 cnd1:1
## group1      0.000                                           
## cond1       0.035  0.000                                    
## hemi1       0.299  0.000  0.133                             
## group1:cnd1 0.000  0.035  0.000 0.000                       
## group1:hem1 0.000  0.299  0.000 0.000 0.133                 
## cond1:hemi1 0.000  0.000  0.000 0.000 0.000   0.000         
## grp1:cnd1:1 0.000  0.000  0.000 0.000 0.000   0.000   0.000

6c) Effect of shock condition – CCN

basedir = '/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw-byshockCond/group/roi/'
d2 = read.csv(paste(basedir,'pe_frontoparietal.csv', sep=''))
glimpse(d2)
## Observations: 960
## Variables: 10
## $ X         <int> 12, 13, 42, 43, 72, 73, 102, 103, 132, 133, 162, 163...
## $ cond      <fctr> CR_safe, CR_safe, FA_safe, FA_safe, sourcehit_safe,...
## $ hemi      <fctr> lh, rh, lh, rh, lh, rh, lh, rh, lh, rh, lh, rh, lh,...
## $ mask_vox  <dbl> 1530, 1802, 1530, 1802, 1530, 1802, 1530, 1802, 1530...
## $ regspace  <fctr> epi, epi, epi, epi, epi, epi, epi, epi, epi, epi, e...
## $ roi       <fctr> frontoparietal, frontoparietal, frontoparietal, fro...
## $ smoothing <fctr> unsmoothed, unsmoothed, unsmoothed, unsmoothed, uns...
## $ subid     <fctr> ap100, ap100, ap100, ap100, ap100, ap100, ap100, ap...
## $ value     <dbl> -742.15948, -1334.28943, 2084.60303, 362.16690, 1286...
## $ group     <fctr> control, control, control, control, control, contro...
data = d2 %>% 
  separate(cond, into = c('this', 'shockCond'), sep = ".*(_)", remove = FALSE) %>%
  separate(cond, into = c('cond', 'that'), sep = "_[^_]*$") %>%
  dplyr::select(-one_of('this', 'that')) %>%
  filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond=factor(cond),
         shockCond=factor(shockCond))
glimpse(data)
## Observations: 320
## Variables: 11
## $ X         <int> 12, 13, 72, 73, 192, 193, 252, 253, 372, 373, 432, 4...
## $ cond      <fctr> CR, CR, sourcehit, sourcehit, CR, CR, sourcehit, so...
## $ shockCond <fctr> safe, safe, safe, safe, threat, threat, threat, thr...
## $ hemi      <fctr> lh, rh, lh, rh, lh, rh, lh, rh, lh, rh, lh, rh, lh,...
## $ mask_vox  <dbl> 1530, 1802, 1530, 1802, 1530, 1802, 1530, 1802, 1366...
## $ regspace  <fctr> epi, epi, epi, epi, epi, epi, epi, epi, epi, epi, e...
## $ roi       <fctr> frontoparietal, frontoparietal, frontoparietal, fro...
## $ smoothing <fctr> unsmoothed, unsmoothed, unsmoothed, unsmoothed, uns...
## $ subid     <fctr> ap100, ap100, ap100, ap100, ap100, ap100, ap100, ap...
## $ value     <dbl> -742.159485, -1334.289429, 1286.854736, -810.972168,...
## $ group     <fctr> control, control, control, control, control, contro...
data %>% group_by(subid, shockCond, group) %>% 
  summarise(n()) %>%
  group_by(shockCond, group) %>% summarise(n())
## Source: local data frame [4 x 3]
## Groups: shockCond [?]
## 
## # A tibble: 4 x 3
##   shockCond   group `n()`
##      <fctr>  <fctr> <int>
## 1      safe control    20
## 2      safe  stress    20
## 3    threat control    20
## 4    threat  stress    20
contrasts(data$group) = c(1, -1); contrasts(data$group)
##         [,1]
## control    1
## stress    -1
contrasts(data$cond) =c(-1,1); contrasts(data$cond)
##           [,1]
## CR          -1
## sourcehit    1
contrasts(data$hemi) =c(1,-1); contrasts(data$hemi)
##    [,1]
## lh    1
## rh   -1
contrasts(data$shockCond) =c(1,-1); contrasts(data$shockCond)
##        [,1]
## safe      1
## threat   -1
# interaction within stress group?
dim(data %>% filter(group == 'stress', hemi == 'lh'))
## [1] 80 11
summary(lmer(value ~ cond*shockCond + (1+cond+shockCond|subid), 
             data=data %>% filter(group == 'stress', hemi == 'lh'))) #interaction n.obs
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ cond * shockCond + (1 + cond + shockCond | subid)
##    Data: data %>% filter(group == "stress", hemi == "lh")
## 
## REML criterion at convergence: 1220.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.83558 -0.49259  0.03846  0.42857  2.41266 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr       
##  subid    (Intercept) 324198   569.4               
##           cond1        72894   270.0     0.42      
##           shockCond1   19768   140.6    -0.48 -1.00
##  Residual             216015   464.8               
## Number of obs: 80, groups:  subid, 20
## 
## Fixed effects:
##                  Estimate Std. Error     df t value Pr(>|t|)    
## (Intercept)        313.78     137.51  19.00   2.282   0.0342 *  
## cond1              505.28      79.65  19.42   6.343 3.94e-06 ***
## shockCond1         -63.36      60.73  24.44  -1.043   0.3070    
## cond1:shockCond1   -60.28      51.96  38.13  -1.160   0.2532    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) cond1  shckC1
## cond1        0.297              
## shockCond1  -0.229 -0.392       
## cnd1:shckC1  0.000  0.000  0.000
# (Intercept)        313.78     137.51  19.00   2.282   0.0342 *  
# cond1              505.28      79.65  19.42   6.343 3.94e-06 ***
# shockCond1         -63.36      60.73  24.44  -1.043   0.3070    
# cond1:shockCond1   -60.28      51.96  38.13  -1.160   0.2532  

summary(lmer(value ~ cond*shockCond*hemi + (1+cond*shockCond+ hemi|subid), 
             data=data %>% filter(group == 'stress')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ cond * shockCond * hemi + (1 + cond * shockCond + hemi |  
##     subid)
##    Data: data %>% filter(group == "stress")
## 
## REML criterion at convergence: 2348.5
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.23273 -0.47086 -0.07589  0.44680  2.00733 
## 
## Random effects:
##  Groups   Name             Variance Std.Dev. Corr                   
##  subid    (Intercept)      252403   502.4                           
##           cond1             70791   266.1     0.04                  
##           shockCond1        48186   219.5    -0.08 -0.51            
##           hemi1             27961   167.2     0.48  0.65 -0.19      
##           cond1:shockCond1  48884   221.1     0.30 -0.05 -0.23  0.32
##  Residual                   66380   257.6                           
## Number of obs: 160, groups:  subid, 20
## 
## Fixed effects:
##                        Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)             64.7658   114.1711  19.0000   0.567 0.577172    
## cond1                  302.0229    62.8841  19.0000   4.803 0.000124 ***
## shockCond1             -54.4050    53.1431  19.0000  -1.024 0.318814    
## hemi1                  249.0117    42.5785  19.0000   5.848 1.24e-05 ***
## cond1:shockCond1       -59.4611    53.4702  19.0000  -1.112 0.279994    
## cond1:hemi1            203.2599    20.3685  57.4400   9.979 3.73e-14 ***
## shockCond1:hemi1        -8.9561    20.3685  57.4400  -0.440 0.661802    
## cond1:shockCond1:hemi1  -0.8226    20.3685  57.4400  -0.040 0.967926    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) cond1  shckC1 hemi1  cn1:C1 cnd1:1 shC1:1
## cond1        0.040                                          
## shockCond1  -0.077 -0.444                                   
## hemi1        0.418  0.543 -0.155                            
## cnd1:shckC1  0.277 -0.046 -0.196  0.257                     
## cond1:hemi1  0.000  0.000  0.000  0.000  0.000              
## shckCnd1:h1  0.000  0.000  0.000  0.000  0.000  0.000       
## cnd1:shC1:1  0.000  0.000  0.000  0.000  0.000  0.000  0.000

6d) Effect of shock condition – DAN

basedir = '/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw-byshockCond/group/roi/'
d2 = read.csv(paste(basedir,'pe_dorsalattn.csv', sep=''))
glimpse(d2)
## Observations: 960
## Variables: 10
## $ X         <int> 14, 15, 44, 45, 74, 75, 104, 105, 134, 135, 164, 165...
## $ cond      <fctr> CR_safe, CR_safe, FA_safe, FA_safe, sourcehit_safe,...
## $ hemi      <fctr> lh, rh, lh, rh, lh, rh, lh, rh, lh, rh, lh, rh, lh,...
## $ mask_vox  <dbl> 726, 695, 726, 695, 726, 695, 726, 695, 726, 695, 72...
## $ regspace  <fctr> epi, epi, epi, epi, epi, epi, epi, epi, epi, epi, e...
## $ roi       <fctr> dorsalattn, dorsalattn, dorsalattn, dorsalattn, dor...
## $ smoothing <fctr> unsmoothed, unsmoothed, unsmoothed, unsmoothed, uns...
## $ subid     <fctr> ap100, ap100, ap100, ap100, ap100, ap100, ap100, ap...
## $ value     <dbl> 94.16875, -685.06036, 3071.22925, 2113.89307, 830.55...
## $ group     <fctr> control, control, control, control, control, contro...
data = d2 %>% 
  separate(cond, into = c('this', 'shockCond'), sep = ".*(_)", remove = FALSE) %>%
  separate(cond, into = c('cond', 'that'), sep = "_[^_]*$") %>%
  dplyr::select(-one_of('this', 'that')) %>%
  filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond=factor(cond),
         shockCond=factor(shockCond))
glimpse(data)
## Observations: 320
## Variables: 11
## $ X         <int> 14, 15, 74, 75, 194, 195, 254, 255, 374, 375, 434, 4...
## $ cond      <fctr> CR, CR, sourcehit, sourcehit, CR, CR, sourcehit, so...
## $ shockCond <fctr> safe, safe, safe, safe, threat, threat, threat, thr...
## $ hemi      <fctr> lh, rh, lh, rh, lh, rh, lh, rh, lh, rh, lh, rh, lh,...
## $ mask_vox  <dbl> 726, 695, 726, 695, 726, 695, 726, 695, 720, 557, 72...
## $ regspace  <fctr> epi, epi, epi, epi, epi, epi, epi, epi, epi, epi, e...
## $ roi       <fctr> dorsalattn, dorsalattn, dorsalattn, dorsalattn, dor...
## $ smoothing <fctr> unsmoothed, unsmoothed, unsmoothed, unsmoothed, uns...
## $ subid     <fctr> ap100, ap100, ap100, ap100, ap100, ap100, ap100, ap...
## $ value     <dbl> 94.16875, -685.06036, 830.55835, -296.97443, 31.3087...
## $ group     <fctr> control, control, control, control, control, contro...
data %>% group_by(subid, shockCond, group) %>% 
  summarise(n()) %>%
  group_by(shockCond, group) %>% summarise(n())
## Source: local data frame [4 x 3]
## Groups: shockCond [?]
## 
## # A tibble: 4 x 3
##   shockCond   group `n()`
##      <fctr>  <fctr> <int>
## 1      safe control    20
## 2      safe  stress    20
## 3    threat control    20
## 4    threat  stress    20
contrasts(data$group) = c(1, -1); contrasts(data$group)
##         [,1]
## control    1
## stress    -1
contrasts(data$cond) =c(-1,1); contrasts(data$cond)
##           [,1]
## CR          -1
## sourcehit    1
contrasts(data$hemi) =c(1,-1); contrasts(data$hemi)
##    [,1]
## lh    1
## rh   -1
contrasts(data$shockCond) =c(1,-1); contrasts(data$shockCond)
##        [,1]
## safe      1
## threat   -1
# interaction within stress group?
dim(data %>% filter(group == 'stress', hemi == 'lh'))
## [1] 80 11
summary(lmer(value ~ cond*shockCond + (1+cond+shockCond|subid), 
             data=data %>% filter(group == 'stress', hemi == 'lh'))) #interaction n.obs
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ cond * shockCond + (1 + cond + shockCond | subid)
##    Data: data %>% filter(group == "stress", hemi == "lh")
## 
## REML criterion at convergence: 1213.8
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.89728 -0.40508  0.08397  0.42095  2.50886 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr       
##  subid    (Intercept) 417423   646.1               
##           cond1        19424   139.4     0.27      
##           shockCond1   50476   224.7    -0.48  0.27
##  Residual             174796   418.1               
## Number of obs: 80, groups:  subid, 20
## 
## Fixed effects:
##                  Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)        960.80     151.84   19.00   6.328 4.51e-06 ***
## cond1              115.33      56.18   19.00   2.053   0.0541 .  
## shockCond1        -104.28      68.62   19.00  -1.520   0.1451    
## cond1:shockCond1   -95.52      46.74   20.50  -2.044   0.0541 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) cond1  shckC1
## cond1        0.140              
## shockCond1  -0.335  0.110       
## cnd1:shckC1  0.000  0.000  0.000
summary(lmer(value ~ cond*shockCond*hemi + (1+cond*shockCond+ hemi|subid), 
             data=data %>% filter(group == 'stress')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ cond * shockCond * hemi + (1 + cond * shockCond + hemi |  
##     subid)
##    Data: data %>% filter(group == "stress")
## 
## REML criterion at convergence: 2266
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.24562 -0.43528 -0.07142  0.45734  2.39872 
## 
## Random effects:
##  Groups   Name             Variance Std.Dev. Corr                   
##  subid    (Intercept)      326781   571.6                           
##           cond1             58642   242.2     0.13                  
##           shockCond1        77988   279.3    -0.26  0.08            
##           hemi1             20711   143.9     0.66 -0.26 -0.62      
##           cond1:shockCond1  43061   207.5     0.55 -0.11 -0.44  0.49
##  Residual                   20981   144.8                           
## Number of obs: 160, groups:  subid, 20
## 
## Fixed effects:
##                        Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)             756.860    128.336  19.000   5.897 1.12e-05 ***
## cond1                    65.897     55.347  19.000   1.191   0.2485    
## shockCond1              -97.803     63.486  19.000  -1.541   0.1399    
## hemi1                   203.939     34.157  19.000   5.971 9.56e-06 ***
## cond1:shockCond1        -93.279     47.793  19.000  -1.952   0.0659 .  
## cond1:hemi1              49.438     11.451  56.700   4.317 6.41e-05 ***
## shockCond1:hemi1         -6.476     11.451  56.700  -0.566   0.5740    
## cond1:shockCond1:hemi1   -2.244     11.451  56.700  -0.196   0.8453    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) cond1  shckC1 hemi1  cn1:C1 cnd1:1 shC1:1
## cond1        0.122                                          
## shockCond1  -0.252  0.081                                   
## hemi1        0.618 -0.243 -0.575                            
## cnd1:shckC1  0.536 -0.100 -0.424  0.450                     
## cond1:hemi1  0.000  0.000  0.000  0.000  0.000              
## shckCnd1:h1  0.000  0.000  0.000  0.000  0.000  0.000       
## cnd1:shC1:1  0.000  0.000  0.000  0.000  0.000  0.000  0.000
# look at interaction
summary(lmer(value ~ cond + (1|subid), 
             data=data %>% filter(group == 'stress', hemi == 'lh', shockCond == 'safe'))) 
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ cond + (1 | subid)
##    Data: data %>% filter(group == "stress", hemi == "lh", shockCond ==  
##     "safe")
## 
## REML criterion at convergence: 606.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.87847 -0.43256  0.06895  0.45898  1.80406 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 312946   559.4   
##  Residual             205107   452.9   
## Number of obs: 40, groups:  subid, 20
## 
## Fixed effects:
##             Estimate Std. Error     df t value Pr(>|t|)    
## (Intercept)   856.52     144.14  19.00   5.942 1.01e-05 ***
## cond1          19.81      71.61  18.89   0.277    0.785    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##       (Intr)
## cond1 0.000
summary(lmer(value ~ cond + (1|subid), 
             data=data %>% filter(group == 'stress', hemi == 'lh', shockCond == 'threat'))) 
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ cond + (1 | subid)
##    Data: data %>% filter(group == "stress", hemi == "lh", shockCond ==  
##     "threat")
## 
## REML criterion at convergence: 617.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.76777 -0.48790  0.04159  0.33508  1.54798 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 584002   764.2   
##  Residual             222181   471.4   
## Number of obs: 40, groups:  subid, 20
## 
## Fixed effects:
##             Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)  1065.08     186.43   19.00   5.713 1.66e-05 ***
## cond1         210.86      74.53   19.52   2.829   0.0105 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##       (Intr)
## cond1 0.000
# interaction by group?
summary(lmer(value ~ cond*shockCond*group + (1+cond+shockCond|subid), 
             data=data %>% filter(hemi == 'lh')))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ cond * shockCond * group + (1 + cond + shockCond | subid)
##    Data: data %>% filter(hemi == "lh")
## 
## REML criterion at convergence: 2411.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.93914 -0.38178  0.03728  0.35496  2.43019 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev. Corr       
##  subid    (Intercept) 377584   614.5               
##           cond1        33559   183.2     0.34      
##           shockCond1   40566   201.4    -0.20  0.08
##  Residual             128068   357.9               
## Number of obs: 160, groups:  subid, 40
## 
## Fixed effects:
##                         Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)              1067.28     101.19   38.00  10.547 7.61e-13 ***
## cond1                     201.96      40.49   38.00   4.988 1.38e-05 ***
## shockCond1                -45.27      42.60   38.00  -1.063   0.2946    
## group1                    106.48     101.19   38.00   1.052   0.2993    
## cond1:shockCond1          -33.07      28.29   35.96  -1.169   0.2501    
## cond1:group1               86.62      40.49   38.00   2.139   0.0389 *  
## shockCond1:group1          59.01      42.60   38.00   1.385   0.1740    
## cond1:shockCond1:group1    62.45      28.29   35.96   2.207   0.0338 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) cond1  shckC1 group1 cn1:C1 cnd1:1 shC1:1
## cond1        0.233                                          
## shockCond1  -0.145  0.042                                   
## group1       0.000  0.000  0.000                            
## cnd1:shckC1  0.000  0.000  0.000  0.000                     
## cond1:grop1  0.000  0.000  0.000  0.233  0.000              
## shckCnd1:g1  0.000  0.000  0.000 -0.145  0.000  0.042       
## cnd1:shC1:1  0.000  0.000  0.000  0.000  0.000  0.000  0.000
dcomb = data %>%
  filter(hemi == 'lh') %>%
  group_by(group, subid, cond, shockCond) %>%
  summarise(mean = mean_(value), n()) %>%
  ungroup() %>%
  mutate(cond = as.character(cond),
         cond = revalue(cond, c("sourcehit" = "HC\nassoc hit")),
         cond = factor(cond, levels=c('HC\nassoc hit', 'CR')),
         shockCond = revalue(shockCond, c("safe" = "Safe")),
         shockCond = revalue(shockCond, c("threat" = "Threat")))
dcomb
## # A tibble: 160 x 6
##      group  subid         cond shockCond       mean `n()`
##     <fctr> <fctr>       <fctr>    <fctr>      <dbl> <int>
##  1 control  ap100           CR      Safe   94.16875     1
##  2 control  ap100           CR    Threat   31.30874     1
##  3 control  ap100 HC
## assoc hit      Safe  830.55835     1
##  4 control  ap100 HC
## assoc hit    Threat  627.75049     1
##  5 control  ap101           CR      Safe 1225.35022     1
##  6 control  ap101           CR    Threat  899.82275     1
##  7 control  ap101 HC
## assoc hit      Safe 1859.50208     1
##  8 control  ap101 HC
## assoc hit    Threat 1769.30457     1
##  9 control  ap102           CR      Safe  455.47006     1
## 10 control  ap102           CR    Threat 1004.34052     1
## # ... with 150 more rows
dplot = data %>%
  filter(hemi == 'lh') %>%
  group_by(group, subid, cond, shockCond) %>%
  summarise(mean_pe = mean_(value)) %>%
  group_by(group, cond, shockCond) %>%
  summarise(mean=mean_(mean_pe), sem=std.error(mean_pe), n=length(mean_pe)) %>%
  ungroup() %>%
  mutate(cond = as.character(cond),
         cond = revalue(cond, c("sourcehit" = "HC\nassoc hit")),
         cond = factor(cond, levels=c('HC\nassoc hit', 'CR')),
         shockCond = revalue(shockCond, c("safe" = "Safe")),
         shockCond = revalue(shockCond, c("threat" = "Threat")))
dplot
## # A tibble: 8 x 6
##     group         cond shockCond      mean      sem     n
##    <fctr>       <fctr>    <fctr>     <dbl>    <dbl> <int>
## 1 control           CR      Safe  869.5471 139.6489    20
## 2 control           CR    Threat  900.8179 127.0413    20
## 3 control HC
## assoc hit      Safe 1505.4680 185.9139    20
## 4 control HC
## assoc hit    Threat 1419.2165 171.1199    20
## 5  stress           CR      Safe  836.7073 134.0977    20
## 6  stress           CR    Threat  854.2198 223.6807    20
## 7  stress HC
## assoc hit      Safe  876.3318 183.9108    20
## 8  stress HC
## assoc hit    Threat 1275.9342 174.8865    20
p2 = ggplot(dplot, aes(x=cond, y=mean, group=group, fill=group)) +
    facet_grid(.~shockCond) +
    geom_bar(position = position_dodge(width=0.9), stat="identity") +
    geom_errorbar(width=0, aes(ymin=mean-sem, 
                               ymax=mean+sem), size=1.5, position=position_dodge(width=0.9)) +
    scale_fill_manual(values=palette, guide = guide_legend(title = NULL)) +
  ylab('Parameter estimate (a.u.)') +
  xlab('')
p2

ggsave('~/Experiments/AP/figs/AP_DAN_byruntype.jpeg', dpi=300, width=8, height=4)

p2

## plot individual subjs

p = ggplot(dcomb, 
       aes(x=cond, y=mean, color=group)) + 
   facet_grid(.~shockCond) +
  geom_point(pch = 19, position = position_jitterdodge(), 
             alpha=.2, size=1.5)+
  scale_x_discrete(name = "Encoding strength") +
  geom_point(data = dplot, aes(y=mean), position=position_dodge(.9), 
             alpha=1, size = 2.5, shape=19) +
  geom_errorbar(data = dplot, width=0,
                aes(y=mean, ymin=mean-sem, ymax=mean+sem),
                size=1.5, position=position_dodge(.9), alpha=1) +
  scale_color_manual(values=palette) +
  ylab('Parameter estimate (a.u.)') +
  xlab('')+
  theme_classic(base_size = 14)+
  theme(legend.title=element_blank(), 
        strip.text = element_text(size=14),
        strip.background = element_rect(colour="white", fill="white"))
## Warning: Ignoring unknown aesthetics: y
p

ggsave('~/Dropbox/Stanford/Papers/AP/Figures/AP_supp_figure5.tiff', dpi=600, width=6.69, height=3)

7) Variability in neural patterns during retrieval

Does the control group have more variable responses across VTC when making SHs? Evidence for “categorical” responses in stress group?

d_2dsd = read.csv('/Volumes/group/awagner/sgagnon/AP/results/retrieval_2dsd_SH_bilat-parahipp_fusi_inftemp_nohipp.csv')

str(d_2dsd)
## 'data.frame':    44 obs. of  5 variables:
##  $ X       : int  0 1 2 3 4 5 6 7 8 9 ...
##  $ subid   : Factor w/ 44 levels "ap100","ap101",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ sh_count: num  88 102 66 113 146 119 124 28 61 20 ...
##  $ sh_2dsd : num  45.1 45.3 48.4 42.5 44.9 ...
##  $ group   : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
d_2dsd %>% group_by(group) %>% summarise(n(), mean(sh_2dsd), std.error(sh_2dsd))
## # A tibble: 2 x 4
##     group `n()` `mean(sh_2dsd)` `std.error(sh_2dsd)`
##    <fctr> <int>           <dbl>                <dbl>
## 1 control    22        44.74340            0.4990321
## 2  stress    22        42.74079            0.6472687
bartlett.test(sh_2dsd ~ group, data=d_2dsd)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  sh_2dsd by group
## Bartlett's K-squared = 1.3722, df = 1, p-value = 0.2414
t.test(sh_2dsd ~ group, data=d_2dsd, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  sh_2dsd by group
## t = 2.4503, df = 42, p-value = 0.01852
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.353220 3.652002
## sample estimates:
## mean in group control  mean in group stress 
##              44.74340              42.74079
summary(lm(sh_2dsd ~ sh_count, data=d_2dsd))
## 
## Call:
## lm(formula = sh_2dsd ~ sh_count, data = d_2dsd)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.2551 -2.0301  0.0787  2.4672  6.5438 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 42.82125    0.95190  44.985   <2e-16 ***
## sh_count     0.01366    0.01259   1.085    0.284    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.858 on 42 degrees of freedom
## Multiple R-squared:  0.02726,    Adjusted R-squared:  0.004099 
## F-statistic: 1.177 on 1 and 42 DF,  p-value: 0.2842
# num of SHs doesn't predict 2dsd

# does this hold when removing poor localizer subjs?
subids_rm = c('ap168', 'ap174') # bad VTC localizer classification
d_2dsd %>% filter(!subid %in% subids_rm) %>% group_by(group) %>% summarise(n(), mean(sh_2dsd), std.error(sh_2dsd))
## # A tibble: 2 x 4
##     group `n()` `mean(sh_2dsd)` `std.error(sh_2dsd)`
##    <fctr> <int>           <dbl>                <dbl>
## 1 control    22        44.74340            0.4990321
## 2  stress    20        42.88347            0.6761959
bartlett.test(sh_2dsd ~ group, data=d_2dsd %>% filter(!subid %in% subids_rm))
## 
##  Bartlett test of homogeneity of variances
## 
## data:  sh_2dsd by group
## Bartlett's K-squared = 1.274, df = 1, p-value = 0.259
t.test(sh_2dsd ~ group, data=d_2dsd %>% filter(!subid %in% subids_rm), var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  sh_2dsd by group
## t = 2.2404, df = 40, p-value = 0.03069
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.1820817 3.5377809
## sample estimates:
## mean in group control  mean in group stress 
##              44.74340              42.88347

7a) Does VTC variability track HC assoc accuracy?

dat = read.csv('/Volumes/group/awagner/sgagnon/AP/results/df_sourceAcc.csv')

dat %>% group_by(subid, group) %>% 
  summarise(mean_acc = mean(mean_acc), n()) %>% 
  group_by(group) %>% 
  summarise(mean(mean_acc), n())
## # A tibble: 2 x 3
##     group `mean(mean_acc)` `n()`
##    <fctr>            <dbl> <int>
## 1 control        0.8185684    23
## 2  stress        0.7387830    23
dat
##     X subid   group  mean_acc sum count
## 1   1 ap100 control 0.8725490  89   102
## 2   2 ap101 control 0.9375000 105   112
## 3   3 ap102 control 0.7010309  68    97
## 4   4 ap103 control 0.8968254 113   126
## 5   5 ap104 control 0.9130435 147   161
## 6   6 ap105 control 0.8623188 119   138
## 7   7 ap106 control 0.5087719  29    57
## 8   8 ap107 control 0.8802817 125   142
## 9   9 ap108 control 0.7073171  29    41
## 10 10 ap109 control 0.6489362  61    94
## 11 11 ap110 control 0.9523810  20    21
## 12 12 ap111 control 0.9012346  73    81
## 13 13 ap113 control 0.8152174  75    92
## 14 14 ap114 control 0.9357798 102   109
## 15 15 ap115 control 0.7428571  78   105
## 16 16 ap116 control 0.9610390 148   154
## 17 17 ap117 control 0.7456140  85   114
## 18 18 ap118 control 0.7682927  63    82
## 19 19 ap119 control 0.8984375 115   128
## 20 20 ap120 control 0.8522727  75    88
## 21 21 ap121 control 0.6415094  34    53
## 22 22 ap122 control 0.8981481  97   108
## 23 23 ap150  stress 0.8800000  66    75
## 24 24 ap152  stress 0.8461538  44    52
## 25 25 ap153  stress 0.7173913  33    46
## 26 26 ap154  stress 0.7931034  46    58
## 27 27 ap155  stress 0.7169811  38    53
## 28 28 ap156  stress 0.3125000   5    16
## 29 29 ap157  stress 0.7794118  53    68
## 30 30 ap158 control 0.7857143  11    14
## 31 31 ap159  stress 0.8360656  51    61
## 32 32 ap160  stress 0.6538462  51    78
## 33 33 ap161  stress 0.5192308  27    52
## 34 34 ap162  stress 0.6567164  44    67
## 35 35 ap163  stress 0.9145299 107   117
## 36 36 ap164  stress 0.9318182  82    88
## 37 37 ap165  stress 0.9154930  65    71
## 38 38 ap166  stress 0.8000000  72    90
## 39 39 ap167  stress 0.6724138  39    58
## 40 40 ap168  stress 0.5000000  46    92
## 41 41 ap169  stress 0.6826923  71   104
## 42 42 ap170  stress 0.9250000  74    80
## 43 43 ap171  stress 0.8048780  33    41
## 44 44 ap172  stress 0.7777778  21    27
## 45 45 ap173  stress 0.4705882   8    17
## 46 46 ap174  stress 0.8854167  85    96
hist(dat$mean_acc)

dat = dat %>% mutate(mean_acc_logit = car::logit(mean_acc))
d_2dsd = dat %>% right_join(d_2dsd, by = c('subid', 'group'))
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
d_2dsd %>% group_by(group) %>% summarise(n(), mean(sh_2dsd), std.error(sh_2dsd))
## # A tibble: 2 x 4
##     group `n()` `mean(sh_2dsd)` `std.error(sh_2dsd)`
##    <fctr> <int>           <dbl>                <dbl>
## 1 control    22        44.74340            0.4990321
## 2  stress    22        42.74079            0.6472687
str(d_2dsd)
## 'data.frame':    44 obs. of  10 variables:
##  $ X.x           : int  1 2 3 4 5 6 8 9 10 11 ...
##  $ subid         : chr  "ap100" "ap101" "ap102" "ap103" ...
##  $ group         : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ mean_acc      : num  0.873 0.938 0.701 0.897 0.913 ...
##  $ sum           : int  89 105 68 113 147 119 125 29 61 20 ...
##  $ count         : int  102 112 97 126 161 138 142 41 94 21 ...
##  $ mean_acc_logit: num  1.924 2.708 0.852 2.162 2.351 ...
##  $ X.y           : int  0 1 2 3 4 5 6 7 8 9 ...
##  $ sh_count      : num  88 102 66 113 146 119 124 28 61 20 ...
##  $ sh_2dsd       : num  45.1 45.3 48.4 42.5 44.9 ...
head(d_2dsd)
##   X.x subid   group  mean_acc sum count mean_acc_logit X.y sh_count
## 1   1 ap100 control 0.8725490  89   102      1.9236870   0       88
## 2   2 ap101 control 0.9375000 105   112      2.7080502   1      102
## 3   3 ap102 control 0.7010309  68    97      0.8522119   2       66
## 4   4 ap103 control 0.8968254 113   126      2.1624385   3      113
## 5   5 ap104 control 0.9130435 147   161      2.3513753   4      146
## 6   6 ap105 control 0.8623188 119   138      1.8346845   5      119
##    sh_2dsd
## 1 45.11144
## 2 45.31822
## 3 48.41050
## 4 42.47459
## 5 44.87312
## 6 41.98806
plot(mean_acc_logit ~ sh_2dsd, data=d_2dsd)

fit1 = lm(mean_acc_logit ~ sh_2dsd, data=d_2dsd)
fit2 = lm(mean_acc_logit ~ poly(sh_2dsd,2), data=d_2dsd)
anova(fit1, fit2) # quad is better, but looks like driven by 2 outliers
## Analysis of Variance Table
## 
## Model 1: mean_acc_logit ~ sh_2dsd
## Model 2: mean_acc_logit ~ poly(sh_2dsd, 2)
##   Res.Df    RSS Df Sum of Sq      F   Pr(>F)   
## 1     42 24.033                                
## 2     41 19.968  1    4.0649 8.3467 0.006147 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
summary(fit1)
## 
## Call:
## lm(formula = mean_acc_logit ~ sh_2dsd, data = d_2dsd)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.66319 -0.58423 -0.03954  0.60094  1.63512 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -3.53252    1.76549  -2.001  0.05190 . 
## sh_2dsd      0.11595    0.04028   2.879  0.00625 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7564 on 42 degrees of freedom
## Multiple R-squared:  0.1648, Adjusted R-squared:  0.1449 
## F-statistic: 8.287 on 1 and 42 DF,  p-value: 0.006255
plot(fit1)

# holds when controlling for group?
contrasts(d_2dsd$group) = c(-1,1)
summary(lm(mean_acc_logit ~ sh_2dsd + group, data=d_2dsd))
## 
## Call:
## lm(formula = mean_acc_logit ~ sh_2dsd + group, data = d_2dsd)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.69814 -0.45212  0.05515  0.59394  1.49419 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -2.73586    1.87703  -1.458   0.1526  
## sh_2dsd      0.09774    0.04283   2.282   0.0278 *
## group1      -0.14581    0.12127  -1.202   0.2361  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7525 on 41 degrees of freedom
## Multiple R-squared:  0.1932, Adjusted R-squared:  0.1539 
## F-statistic:  4.91 on 2 and 41 DF,  p-value: 0.01225
# what about removing VTC outliers?
plot(mean_acc_logit ~ sh_2dsd, data=d_2dsd %>% filter(!subid %in% subids_rm))

summary(lm(mean_acc_logit ~ sh_2dsd, data=d_2dsd %>% filter(!subid %in% subids_rm)))
## 
## Call:
## lm(formula = mean_acc_logit ~ sh_2dsd, data = d_2dsd %>% filter(!subid %in% 
##     subids_rm))
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.58105 -0.52582 -0.09643  0.63637  1.62629 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -2.83575    1.84242  -1.539   0.1316  
## sh_2dsd      0.10032    0.04192   2.393   0.0215 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.7559 on 40 degrees of freedom
## Multiple R-squared:  0.1252, Adjusted R-squared:  0.1033 
## F-statistic: 5.725 on 1 and 40 DF,  p-value: 0.02151

Does 2dsd explain variance in hipp -> sourceAcc not explained by VTC?

vtc = read.csv('/Volumes/group/awagner/sgagnon/AP/results/sourcehit_avglogit_vtc.csv')
vtc = vtc %>% mutate(mean_logit = mean) %>% dplyr::select(-mean)

d_2dsd = read.csv('/Volumes/group/awagner/sgagnon/AP/results/retrieval_2dsd_SH_bilat-parahipp_fusi_inftemp_nohipp.csv')

roi = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/pe_sourcehit-cr_zstat1_peak1_5mm_sphere_masked.nii.csv')
roi = roi %>% filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond)) %>% 
  dplyr::select(subid, group, cond, value) %>%  # calc diff score
  spread(key = cond, value=value) %>%
  mutate(diff = sourcehit - CR) %>%
  right_join(d_2dsd, by = c('subid', 'group')) %>%
  right_join(vtc, by = c('subid', 'group')) %>%
  left_join(dat, by = c('subid', 'group')) %>%
  mutate(diff_orig = diff,
         diff = as.numeric(scale(diff)),
         mean_logit = as.numeric(scale(mean_logit)),
         mean_acc = as.numeric(scale(car::logit(mean_acc))),
         sh_2dsd = as.numeric(scale(sh_2dsd)))
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector
dim(roi)
## [1] 42 16
str(roi)
## 'data.frame':    42 obs. of  16 variables:
##  $ subid         : chr  "ap100" "ap101" "ap102" "ap103" ...
##  $ group         : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ CR            : num  -396 320 107 -519 -416 ...
##  $ sourcehit     : num  379.9 990.6 891.5 90.7 -99.2 ...
##  $ diff          : num  0.924 0.652 0.945 0.495 -0.263 ...
##  $ X.x           : int  0 1 2 3 4 5 6 7 8 9 ...
##  $ sh_count      : num  88 102 66 113 146 119 124 28 61 20 ...
##  $ sh_2dsd       : num  0.445 0.519 1.617 -0.491 0.361 ...
##  $ X.y           : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ mean_logit    : num  0.3483 -0.2448 0.7178 -0.8012 -0.0116 ...
##  $ X             : int  1 2 3 4 5 6 8 9 10 11 ...
##  $ mean_acc      : num  0.451 1.433 -0.892 0.75 0.987 ...
##  $ sum           : int  89 105 68 113 147 119 125 29 61 20 ...
##  $ count         : int  102 112 97 126 161 138 142 41 94 21 ...
##  $ mean_acc_logit: num  1.924 2.708 0.852 2.162 2.351 ...
##  $ diff_orig     : num  776 671 784 610 317 ...
contrasts(roi$group) = c(1,-1)

summary(lm(mean_acc ~ mean_logit + diff + sh_2dsd, data=roi))
## 
## Call:
## lm(formula = mean_acc ~ mean_logit + diff + sh_2dsd, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.87604 -0.34214 -0.07273  0.53240  1.86639 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)   
## (Intercept) -3.794e-16  1.293e-01   0.000  1.00000   
## mean_logit  -8.283e-02  1.625e-01  -0.510  0.61318   
## diff         5.130e-01  1.533e-01   3.347  0.00185 **
## sh_2dsd      3.115e-01  1.403e-01   2.220  0.03248 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8378 on 38 degrees of freedom
## Multiple R-squared:  0.3494, Adjusted R-squared:  0.298 
## F-statistic: 6.803 on 3 and 38 DF,  p-value: 0.0008786
summary(lm(mean_logit ~ sh_2dsd, data=roi))
## 
## Call:
## lm(formula = mean_logit ~ sh_2dsd, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.50446 -0.42701  0.06335  0.58201  2.12063 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -2.607e-16  1.459e-01   0.000   1.0000  
## sh_2dsd      3.572e-01  1.477e-01   2.419   0.0202 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9456 on 40 degrees of freedom
## Multiple R-squared:  0.1276, Adjusted R-squared:  0.1058 
## F-statistic: 5.851 on 1 and 40 DF,  p-value: 0.02021
# Is hipp effect on source acc mediated by 2dsd?
contrasts(roi$group) = c(1,-1)

model.t = lm(mean_acc ~ diff, data=roi); summary(model.t) 
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.24505 -0.45864 -0.00737  0.52330  1.87362 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.116e-16  1.340e-01   0.000 1.000000    
## diff         5.138e-01  1.356e-01   3.788 0.000501 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8686 on 40 degrees of freedom
## Multiple R-squared:  0.264,  Adjusted R-squared:  0.2456 
## F-statistic: 14.35 on 1 and 40 DF,  p-value: 0.0005012
#               Estimate Std. Error t value Pr(>|t|)    
# (Intercept) -2.593e-17  1.340e-01   0.000 1.000000    
# diff         5.138e-01  1.356e-01   3.788 0.000501 ***
model.m = lm(sh_2dsd ~ diff, data=roi); summary(model.m)
## 
## Call:
## lm(formula = sh_2dsd ~ diff, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.4071 -0.7691  0.1440  0.7134  2.4809 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) 8.713e-16  1.547e-01   0.000    1.000
## diff        1.403e-01  1.565e-01   0.896    0.375
## 
## Residual standard error: 1.002 on 40 degrees of freedom
## Multiple R-squared:  0.01969,    Adjusted R-squared:  -0.004819 
## F-statistic: 0.8034 on 1 and 40 DF,  p-value: 0.3755
#              Estimate Std. Error t value Pr(>|t|)    
# (Intercept) 8.713e-16  1.547e-01   0.000    1.000
# diff        1.403e-01  1.565e-01   0.896    0.375
model.y = lm(mean_acc ~ sh_2dsd + diff, data=roi); summary(model.y)
## 
## Call:
## lm(formula = mean_acc ~ sh_2dsd + diff, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.8909 -0.3753 -0.1001  0.4779  1.8724 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -3.620e-16  1.280e-01   0.000 1.000000    
## sh_2dsd      2.874e-01  1.309e-01   2.196 0.034119 *  
## diff         4.735e-01  1.309e-01   3.617 0.000844 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8298 on 39 degrees of freedom
## Multiple R-squared:  0.345,  Adjusted R-squared:  0.3114 
## F-statistic: 10.27 on 2 and 39 DF,  p-value: 0.0002614
#               Estimate Std. Error t value Pr(>|t|)   
# (Intercept) -2.764e-16  1.280e-01   0.000 1.000000    
# sh_2dsd      2.874e-01  1.309e-01   2.196 0.034119 *  
# diff         4.735e-01  1.309e-01   3.617 0.000844 ***
model.other = lm(mean_acc ~ sh_2dsd, data=roi); summary(model.other)
## 
## Call:
## lm(formula = mean_acc ~ sh_2dsd, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.9807 -0.6587 -0.1208  0.7972  2.0374 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -4.119e-16  1.461e-01   0.000   1.0000  
## sh_2dsd      3.539e-01  1.479e-01   2.393   0.0215 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9469 on 40 degrees of freedom
## Multiple R-squared:  0.1252, Adjusted R-squared:  0.1033 
## F-statistic: 5.725 on 1 and 40 DF,  p-value: 0.02151
# (Intercept) -3.263e-16  1.461e-01   0.000   1.0000  
# sh_2dsd      3.539e-01  1.479e-01   2.393   0.0215 *

ggplot(roi, aes(x=sh_2dsd, y=mean_acc)) +
  geom_point() +   
  geom_smooth(method=lm) +
  xlab('SH 2dsd') +
  ylab('Source accuracy (logit)')

roi %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    20
## Bootstrapping Confidence Interval (BCa and Percentile)
boot.med <- function(data, indices){
    data <-data[indices,]   #this does the random resampling of rows

    reg1 <- lm(sh_2dsd ~ diff, data=data)
    reg2 <- lm(mean_acc ~ sh_2dsd + diff, data=data)
    
    a <- coefficients(reg1)["diff"] #the a path coefficient
    b <- coefficients(reg2)["sh_2dsd"]  #the b path coefficient
    a*b                         #returns the product of a*b
}

medboot<-boot(data=roi, statistic = boot.med, R=5000)   
mean(medboot$t)
## [1] 0.05266069
quantile(medboot$t, c(0.025, 0.975))
##        2.5%       97.5% 
## -0.08500636  0.24561459
# > mean(medboot$t)
# [1] 0.05026415
# > quantile(medboot$t, c(0.025, 0.975))
#        2.5%       97.5% 
# -0.08661536  0.23665193 

Supplemental stats

S1) Encoding performance

Encoding: RT

d = ds %>% 
  filter(resp != 'no response') %>%
  mutate(resp = factor(resp)) %>%
  group_by(group, subid, repCount, repType, cond) %>%
  summarise(rt = median_(respRT)) %>%
  ungroup()

res = lmer(rt ~ (cond + scale(repCount) * repType) * group +
             (1 + cond + scale(repCount) * repType|subid), data=d,
           control=lmerControl(optCtrl=list(maxfun=1e5)), REML=TRUE)
summary(res)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt ~ (cond + scale(repCount) * repType) * group + (1 + cond +  
##     scale(repCount) * repType | subid)
##    Data: d
## Control: lmerControl(optCtrl = list(maxfun = 1e+05))
## 
## REML criterion at convergence: -300.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.5719 -0.4774  0.0681  0.5825  2.6085 
## 
## Random effects:
##  Groups   Name                     Variance  Std.Dev. Corr             
##  subid    (Intercept)              7.269e-02 0.269618                  
##           cond1                    1.833e-05 0.004281 -0.58            
##           scale(repCount)          2.313e-02 0.152097  0.33  0.58      
##           repType1                 4.070e-03 0.063797 -0.67 -0.22 -0.92
##           scale(repCount):repType1 5.547e-03 0.074481 -0.66 -0.22 -0.92
##  Residual                          1.952e-02 0.139725                  
##       
##       
##       
##       
##       
##   1.00
##       
## Number of obs: 564, groups:  subid, 47
## 
## Fixed effects:
##                                   Estimate Std. Error         df t value
## (Intercept)                       1.602587   0.040419  45.000000  39.650
## cond1                            -0.003430   0.005918 383.000000  -0.580
## scale(repCount)                  -0.239199   0.024956  45.500000  -9.585
## repType1                         -0.001237   0.013150  54.200000  -0.094
## group1                            0.029139   0.040419  45.000000   0.721
## scale(repCount):repType1          0.052630   0.015763  57.500000   3.339
## cond1:group1                     -0.001723   0.005918 383.000000  -0.291
## scale(repCount):group1            0.020218   0.024956  45.500000   0.810
## repType1:group1                  -0.016456   0.013150  54.200000  -1.251
## scale(repCount):repType1:group1  -0.010379   0.015763  57.500000  -0.658
##                                 Pr(>|t|)    
## (Intercept)                      < 2e-16 ***
## cond1                            0.56256    
## scale(repCount)                 1.73e-12 ***
## repType1                         0.92539    
## group1                           0.47468    
## scale(repCount):repType1         0.00148 ** 
## cond1:group1                     0.77105    
## scale(repCount):group1           0.42209    
## repType1:group1                  0.21616    
## scale(repCount):repType1:group1  0.51290    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) cond1  scl(C) rpTyp1 group1 sc(C):T1 cnd1:1 s(C):1
## cond1       -0.060                                                   
## scal(rpCnt)  0.353  0.054                                            
## repType1    -0.570 -0.016 -0.817                                     
## group1      -0.021  0.001 -0.008  0.012                              
## scl(rpC):T1 -0.567 -0.016 -0.838  0.827  0.012                       
## cond1:grop1  0.001 -0.021 -0.001  0.000 -0.060  0.000                
## scl(rpCn):1 -0.008 -0.001 -0.021  0.017  0.353  0.018    0.054       
## rpTyp1:grp1  0.012  0.000  0.017 -0.021 -0.570 -0.018   -0.016 -0.817
## scl(C):T1:1  0.012  0.000  0.018 -0.018 -0.567 -0.021   -0.016 -0.838
##             rpT1:1
## cond1             
## scal(rpCnt)       
## repType1          
## group1            
## scl(rpC):T1       
## cond1:grop1       
## scl(rpCn):1       
## rpTyp1:grp1       
## scl(C):T1:1  0.827
summary(lmer(rt ~ (cond + scale(repCount)) * group +
             (1 + scale(repCount)|subid), # remove cond to converge
             data=d %>% filter(repType == '2'),
           control=lmerControl(optCtrl=list(maxfun=1e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt ~ (cond + scale(repCount)) * group + (1 + scale(repCount) |  
##     subid)
##    Data: d %>% filter(repType == "2")
## Control: lmerControl(optCtrl = list(maxfun = 1e+05))
## 
## REML criterion at convergence: -113.3
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -1.90854 -0.56696 -0.02986  0.52469  2.07304 
## 
## Random effects:
##  Groups   Name            Variance Std.Dev. Corr
##  subid    (Intercept)     0.071518 0.26743      
##           scale(repCount) 0.013333 0.11547  0.17
##  Residual                 0.005605 0.07487      
## Number of obs: 188, groups:  subid, 47
## 
## Fixed effects:
##                         Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)             1.785967   0.039398 45.000000  45.332  < 2e-16 ***
## cond1                  -0.004509   0.005462 92.000000  -0.826    0.411    
## scale(repCount)        -0.136972   0.017714 45.000000  -7.732 8.48e-10 ***
## group1                  0.026499   0.039398 45.000000   0.673    0.505    
## cond1:group1            0.005357   0.005462 92.000000   0.981    0.329    
## scale(repCount):group1  0.014360   0.017714 45.000000   0.811    0.422    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) cond1  scl(C) group1 cnd1:1
## cond1        0.000                            
## scal(rpCnt)  0.159  0.000                     
## group1      -0.021  0.000 -0.003              
## cond1:grop1  0.000 -0.021  0.000  0.000       
## scl(rpCn):1 -0.003  0.000 -0.021  0.159  0.000
summary(lmer(rt ~ (cond + scale(repCount)) * group +
             (1 + scale(repCount)|subid), # remove cond to converge
             data=d %>% filter(repType == '4'),
           control=lmerControl(optCtrl=list(maxfun=1e5))))
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: rt ~ (cond + scale(repCount)) * group + (1 + scale(repCount) |  
##     subid)
##    Data: d %>% filter(repType == "4")
## Control: lmerControl(optCtrl = list(maxfun = 1e+05))
## 
## REML criterion at convergence: -84.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.92638 -0.55847  0.08084  0.57011  2.36995 
## 
## Random effects:
##  Groups   Name            Variance Std.Dev. Corr 
##  subid    (Intercept)     0.051025 0.22589       
##           scale(repCount) 0.007068 0.08407  -0.08
##  Residual                 0.026193 0.16184       
## Number of obs: 376, groups:  subid, 47
## 
## Fixed effects:
##                          Estimate Std. Error         df t value Pr(>|t|)
## (Intercept)              1.543127   0.033997  45.000000  45.390   <2e-16
## cond1                   -0.002890   0.008348 280.000000  -0.346    0.729
## scale(repCount)         -0.195545   0.014844  45.000000 -13.173   <2e-16
## group1                   0.015753   0.033997  45.000000   0.463    0.645
## cond1:group1            -0.005264   0.008348 280.000000  -0.631    0.529
## scale(repCount):group1   0.010312   0.014844  45.000000   0.695    0.491
##                           
## (Intercept)            ***
## cond1                     
## scale(repCount)        ***
## group1                    
## cond1:group1              
## scale(repCount):group1    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) cond1  scl(C) group1 cnd1:1
## cond1        0.000                            
## scal(rpCnt) -0.064  0.000                     
## group1      -0.021  0.000  0.001              
## cond1:grop1  0.000 -0.021  0.000  0.000       
## scl(rpCn):1  0.001  0.000 -0.021 -0.064  0.000

S2) Compare item vs. assoc dprime (Wixted approach)

item_d = read.csv('/Volumes/group/awagner/sgagnon/AP/results/behav_item_dprime.csv')
assoc_d = read.csv('/Volumes/group/awagner/sgagnon/AP/results/behav_assoc_dprime.csv')

# merge these 2 measures:
item_d = item_d %>% 
  dplyr::select(subid, group, dprime) %>%
  group_by(subid, group) %>%
  summarise(item_d = mean(dprime))

assoc_d = assoc_d %>% 
  dplyr::select(subid, group, dprime) %>%
  group_by(subid, group) %>%
  summarise(assoc_d = mean(dprime))

combined_d = item_d %>% left_join(assoc_d)
## Joining, by = c("subid", "group")
combined_d
## Source: local data frame [47 x 4]
## Groups: subid [?]
## 
## # A tibble: 47 x 4
##     subid   group    item_d   assoc_d
##    <fctr>  <fctr>     <dbl>     <dbl>
##  1  ap100 control 1.6545387 1.5923038
##  2  ap101 control 2.8518891 2.0702869
##  3  ap102 control 1.2563972 0.7773663
##  4  ap103 control 2.5178107 2.0206085
##  5  ap104 control 3.7519274 2.7741996
##  6  ap105 control 2.8281077 1.8557002
##  7  ap106 control 1.3389959 0.1081459
##  8  ap107 control 2.0413809 2.0035682
##  9  ap108 control 0.6659922 0.4459195
## 10  ap109 control 1.1989806 0.5196194
## # ... with 37 more rows
## Wixted 2004 standardized measure:

# make sure no major outliers biasing sd!
boxplot(combined_d %>% filter(group == 'control') %>% 
  dplyr::select(item_d, assoc_d))
## Adding missing grouping variables: `subid`
stripchart(combined_d %>% filter(group == 'control') %>% 
  dplyr::select(item_d, assoc_d), vertical = TRUE, method = "jitter", add=TRUE)
## Adding missing grouping variables: `subid`

# get control group stats for standardizing
sum_stats = combined_d %>% filter(group == 'control') %>% 
  ungroup() %>%
  dplyr::select(item_d, assoc_d) %>%
  summarise_each(funs(mean, sd, n()))
sum_stats
## # A tibble: 1 x 6
##   item_d_mean assoc_d_mean item_d_sd assoc_d_sd item_d_n assoc_d_n
##         <dbl>        <dbl>     <dbl>      <dbl>    <int>     <int>
## 1    1.894499     1.366334 0.8853859  0.7938154       23        23
# get stress standardized by control stats
rel_control = combined_d %>% 
  ungroup() %>%
  mutate(item_z = (item_d - sum_stats$item_d_mean)/sum_stats$item_d_sd,
         assoc_z = (assoc_d - sum_stats$assoc_d_mean)/sum_stats$assoc_d_sd) %>% 
  filter(group == 'stress') %>%
  dplyr::select(subid, group, item_z, assoc_z) %>%
  gather(key='dprimetype', value='zscore', item_z:assoc_z)

rel_control %>%
  group_by(dprimetype) %>%
  summarise_each(funs(mean))
## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA

## Warning in mean.default(structure(c(23L, 24L, 25L, 26L, 27L, 28L, 29L,
## 30L, : argument is not numeric or logical: returning NA
## Warning in mean.default(structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, :
## argument is not numeric or logical: returning NA

## Warning in mean.default(structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, :
## argument is not numeric or logical: returning NA
## # A tibble: 2 x 4
##   dprimetype subid group     zscore
##        <chr> <lgl> <lgl>      <dbl>
## 1    assoc_z    NA    NA -0.7129529
## 2     item_z    NA    NA -0.4695853
# stats:
bartlett.test(zscore ~ dprimetype, data=rel_control)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  zscore by dprimetype
## Bartlett's K-squared = 0.47665, df = 1, p-value = 0.4899
t.test(zscore ~ dprimetype, data=rel_control, var.equal=TRUE, paired=TRUE)
## 
##  Paired t-test
## 
## data:  zscore by dprimetype
## t = -1.9115, df = 23, p-value = 0.06848
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.5067463  0.0200110
## sample estimates:
## mean of the differences 
##              -0.2433676

S3) Associative accuracy (behavioral inclusion criteria) by encoding strength and run type (safe, threat)

High confidence assoc accuracy

dat = dtest %>% 
  filter(subj_status == 'old', 
         reps > 0,
         conf == 'Hi') %>%
  group_by(subid, group) %>%
  summarise(mean_acc = mean(acc_num), sum=sum(acc_num), count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), fill = list(mean_acc=0,
                                                    count=0))

dim(dat) # all subjs included
## [1] 47  5
dat %>% filter(count < 6) 
## # A tibble: 1 x 5
##    subid  group mean_acc   sum count
##   <fctr> <fctr>    <dbl> <dbl> <dbl>
## 1  ap151 stress      0.6     3     5
# ap151

rm_subids = dat %>% filter(count < 6) %>% pull(subid) %>% unique(); rm_subids
## [1] ap151
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
rm_subids # ap151
## [1] ap151
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
dat = dat %>% filter(!subid %in% rm_subids)

dat %>% group_by(subid, group) %>% 
  summarise(mean_acc = mean(mean_acc), n()) %>% 
  group_by(group) %>% 
  summarise(mean(mean_acc), n())
## # A tibble: 2 x 3
##     group `mean(mean_acc)` `n()`
##    <fctr>            <dbl> <int>
## 1 control        0.8185684    23
## 2  stress        0.7387830    23
hist(dat$mean_acc) # skewed negatively

# logit transform
dat = dat %>% mutate(mean_acc_logit = car::logit(mean_acc))
hist(dat$mean_acc_logit)

boxplot(dat$mean_acc_logit)

# stats:
dat %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    23
## 2  stress    23
bartlett.test(mean_acc_logit ~ group, data=dat)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean_acc_logit by group
## Bartlett's K-squared = 0.14041, df = 1, p-value = 0.7079
t.test(mean_acc_logit ~ group, data=dat, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  mean_acc_logit by group
## t = 1.9585, df = 44, p-value = 0.05653
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.01457236  1.01850230
## sample estimates:
## mean in group control  mean in group stress 
##              1.706974              1.205009
dat_control = dat %>% filter(group == 'control')
t.test(x=dat_control$mean_acc_logit, mu = 0)
## 
##  One Sample t-test
## 
## data:  dat_control$mean_acc_logit
## t = 9.8233, df = 22, p-value = 1.668e-09
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  1.346600 2.067347
## sample estimates:
## mean of x 
##  1.706974
dat_control = dat %>% filter(group == 'stress')
t.test(x=dat_control$mean_acc_logit, mu = 0)
## 
##  One Sample t-test
## 
## data:  dat_control$mean_acc_logit
## t = 6.3961, df = 22, p-value = 1.953e-06
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.8142949 1.5957230
## sample estimates:
## mean of x 
##  1.205009
# logit(.5) = 0 # when acc=50%, logit = 0

P(correct | “high conf old” to old item), broken down by study reps

with(dtest %>% 
  filter(subj_status == 'old', 
         reps > 0,
         conf == 'Hi'), table(acc, acc_num))
##              acc_num
## acc              0    1
##   CR             0    0
##   FA             0    0
##   H              0 3025
##   M              0    0
##   no response    0    0
##   SM           706    0
# just split by study reps
dat = dtest %>% 
  filter(subj_status == 'old', 
         reps > 0,
         conf == 'Hi') %>%
  group_by(subid, group, reps) %>%
  summarise(mean_acc = mean(acc_num), count=n()) %>%
  ungroup() %>%
  mutate(reps = factor(reps)) %>%
  complete(nesting(subid, group), reps, fill = list(mean_acc=0,
                                                    count=0))

dim(dat) # all subjs included
## [1] 94  5
dat %>% filter(count < 6) 
## # A tibble: 4 x 5
##    subid   group   reps mean_acc count
##   <fctr>  <fctr> <fctr>    <dbl> <dbl>
## 1  ap110 control      2     0.75     4
## 2  ap151  stress      2     0.00     1
## 3  ap151  stress      4     0.75     4
## 4  ap158 control      2     0.50     4
dat
## # A tibble: 94 x 5
##     subid   group   reps  mean_acc count
##    <fctr>  <fctr> <fctr>     <dbl> <dbl>
##  1  ap100 control      2 0.9090909    44
##  2  ap100 control      4 0.8448276    58
##  3  ap101 control      2 0.8444444    45
##  4  ap101 control      4 1.0000000    67
##  5  ap102 control      2 0.6388889    36
##  6  ap102 control      4 0.7377049    61
##  7  ap103 control      2 0.8727273    55
##  8  ap103 control      4 0.9154930    71
##  9  ap104 control      2 0.8607595    79
## 10  ap104 control      4 0.9634146    82
## # ... with 84 more rows
rm_subids = dat %>% filter(count < 6) %>% pull(subid) %>% unique(); rm_subids
## [1] ap110 ap151 ap158
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
# 2 control, 1 stress
dat = dat %>% filter(!subid %in% rm_subids)
dat
## # A tibble: 88 x 5
##     subid   group   reps  mean_acc count
##    <fctr>  <fctr> <fctr>     <dbl> <dbl>
##  1  ap100 control      2 0.9090909    44
##  2  ap100 control      4 0.8448276    58
##  3  ap101 control      2 0.8444444    45
##  4  ap101 control      4 1.0000000    67
##  5  ap102 control      2 0.6388889    36
##  6  ap102 control      4 0.7377049    61
##  7  ap103 control      2 0.8727273    55
##  8  ap103 control      4 0.9154930    71
##  9  ap104 control      2 0.8607595    79
## 10  ap104 control      4 0.9634146    82
## # ... with 78 more rows
dat %>% group_by(subid, group) %>% summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    21
## 2  stress    23
dat = dat%>% mutate(mean_logit = car::logit(mean_acc))
## Warning in car::logit(c(0.909090909090909, 0.844827586206897,
## 0.844444444444444, : proportions remapped to (0.025, 0.975)
contrasts(dat$reps) = c(-1,1); contrasts(dat$reps)
##   [,1]
## 2   -1
## 4    1
contrasts(dat$group) = c(1,-1); contrasts(dat$group)
##         [,1]
## control    1
## stress    -1
summary(lmer(mean_logit ~ group*reps + 
               (1|subid), data=dat)) # not enough obs for the RE
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: mean_logit ~ group * reps + (1 | subid)
##    Data: dat
## 
## REML criterion at convergence: 179.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.04808 -0.46015  0.01082  0.44168  2.70514 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.5407   0.7353  
##  Residual             0.1326   0.3641  
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   1.30047    0.11757 42.00000  11.061 5.06e-14 ***
## group1        0.21906    0.11757 42.00000   1.863 0.069437 .  
## reps1         0.15390    0.03886 42.00000   3.961 0.000283 ***
## group1:reps1  0.02946    0.03886 42.00000   0.758 0.452555    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 reps1
## group1      0.045              
## reps1       0.000  0.000       
## group1:rps1 0.000  0.000  0.045

P(correct | “high conf old” to old item), broken down by shock condition

# just split by study reps
dat = dtest %>% 
  filter(subj_status == 'old', 
         reps > 0,
         conf == 'Hi') %>%
  group_by(subid, group, shockCond) %>%
  summarise(mean_acc = mean(acc_num), count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, fill = list(mean_acc=0,
                                                         count=0))

dim(dat) # all subjs included
## [1] 94  5
dat %>% filter(count < 6) 
## # A tibble: 4 x 5
##    subid  group shockCond mean_acc count
##   <fctr> <fctr>    <fctr>    <dbl> <dbl>
## 1  ap151 stress      safe     0.50     4
## 2  ap151 stress    threat     1.00     1
## 3  ap156 stress      safe     0.00     4
## 4  ap173 stress    threat     0.25     4
# many low trial counts/bin!

rm_subids = dat %>% filter(count < 6) %>% pull(subid) %>% unique()
dat = dat %>% filter(!subid %in% rm_subids)

dat %>% group_by(subid, group) %>% summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    23
## 2  stress    21
dat = dat%>% mutate(mean_logit = car::logit(mean_acc))
## Warning in car::logit(c(0.901960784313726, 0.843137254901961,
## 0.947368421052632, : proportions remapped to (0.025, 0.975)
contrasts(dat$shockCond) = c(1,-1); contrasts(dat$shockCond)
##        [,1]
## safe      1
## threat   -1
contrasts(dat$group) = c(1,-1); contrasts(dat$group)
##         [,1]
## control    1
## stress    -1
summary(lmer(mean_logit ~ group*shockCond + 
               (1|subid), data=dat)) # not enough obs for the RE
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: mean_logit ~ group * shockCond + (1 | subid)
##    Data: dat
## 
## REML criterion at convergence: 206.4
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.67278 -0.44126 -0.06186  0.46657  3.14956 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.3756   0.6128  
##  Residual             0.2922   0.5405  
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)        1.45029    0.10900 42.00000  13.306   <2e-16 ***
## group1             0.16350    0.10900 42.00000   1.500    0.141    
## shockCond1        -0.03931    0.05768 42.00000  -0.681    0.499    
## group1:shockCond1  0.02327    0.05768 42.00000   0.403    0.689    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1
## group1      -0.045              
## shockCond1   0.000  0.000       
## grp1:shckC1  0.000  0.000 -0.045
# what about just within stress
summary(lmer(mean_logit ~ shockCond + 
               (1|subid), data=dat %>% filter(group == 'stress'))) # not enough obs for the RE
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: mean_logit ~ shockCond + (1 | subid)
##    Data: dat %>% filter(group == "stress")
## 
## REML criterion at convergence: 88
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.5070 -0.4060  0.0047  0.4600  2.2673 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.3802   0.6166  
##  Residual             0.1997   0.4469  
## Number of obs: 42, groups:  subid, 21
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)  1.28679    0.15119 20.00000   8.511 4.42e-08 ***
## shockCond1  -0.06258    0.06895 20.00000  -0.908    0.375    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##            (Intr)
## shockCond1 0.000

Low confidence assoc accuracy

dat = dtest %>% 
  filter(subj_status == 'old', 
         reps > 0,
         conf == 'Lo') %>%
  group_by(subid, group) %>%
  summarise(mean_acc = mean(acc_num), count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), fill = list(mean_acc=0,
                                                    count=0))

dim(dat) # all subjs included
## [1] 46  4
dat %>% filter(count < 6) 
## # A tibble: 3 x 4
##    subid   group  mean_acc count
##   <fctr>  <fctr>     <dbl> <dbl>
## 1  ap116 control 0.6666667     3
## 2  ap160  stress 1.0000000     1
## 3  ap169  stress 0.0000000     2
# dat %>% filter(subid == 'ap156')
# many low trial counts/bin!

rm_subids = dat %>% filter(count < 6) %>% pull(subid) %>% unique(); rm_subids
## [1] ap116 ap160 ap169
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
dat = dat %>% filter(!subid %in% rm_subids)

dat %>% group_by(subid, group) %>% summarise(n(), mean_acc = mean(mean_acc)) %>% group_by(group) %>% summarise(n(), mean(mean_acc))
## # A tibble: 2 x 3
##     group `n()` `mean(mean_acc)`
##    <fctr> <int>            <dbl>
## 1 control    21        0.5685041
## 2  stress    22        0.5152346
hist(dat$mean_acc)

dat = dat%>% mutate(mean_acc_logit = car::logit(mean_acc))
hist(dat$mean_acc_logit)

bartlett.test(mean_acc_logit ~ group, data=dat)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean_acc_logit by group
## Bartlett's K-squared = 3.1647, df = 1, p-value = 0.07525
t.test(mean_acc_logit ~ group, data=dat, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  mean_acc_logit by group
## t = 2.5569, df = 41, p-value = 0.01436
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.04654901 0.39641939
## sample estimates:
## mean in group control  mean in group stress 
##            0.28273408            0.06124988
dat_control = dat %>% filter(group == 'control')
t.test(x=dat_control$mean_acc_logit, mu = 0)
## 
##  One Sample t-test
## 
## data:  dat_control$mean_acc_logit
## t = 3.8644, df = 20, p-value = 0.0009659
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.1301165 0.4353517
## sample estimates:
## mean of x 
## 0.2827341
dat_control = dat %>% filter(group == 'stress')
t.test(x=dat_control$mean_acc_logit, mu = 0)
## 
##  One Sample t-test
## 
## data:  dat_control$mean_acc_logit
## t = 1.2805, df = 21, p-value = 0.2143
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.03822232  0.16072209
## sample estimates:
##  mean of x 
## 0.06124988
dat
## # A tibble: 43 x 5
##     subid   group  mean_acc count mean_acc_logit
##    <fctr>  <fctr>     <dbl> <dbl>          <dbl>
##  1  ap100 control 0.4400000    25    -0.24116206
##  2  ap101 control 0.6666667    21     0.69314718
##  3  ap102 control 0.4285714    63    -0.28768207
##  4  ap103 control 0.5909091    22     0.36772478
##  5  ap105 control 0.7058824    17     0.87546874
##  6  ap106 control 0.6400000    75     0.57536414
##  7  ap107 control 0.6470588    17     0.60613580
##  8  ap108 control 0.6086957    69     0.44183275
##  9  ap109 control 0.5000000    46     0.00000000
## 10  ap110 control 0.5140187   107     0.05608947
## # ... with 33 more rows

P(correct | “low conf old” to old item), broken down by study reps

# just split by study reps
dat = dtest %>% 
  filter(subj_status == 'old', 
         reps > 0,
         conf == 'Lo') %>%
  group_by(subid, group, reps) %>%
  summarise(mean_acc = mean(acc_num), count=n()) %>%
  ungroup() %>%
  mutate(reps = factor(reps)) %>%
  complete(nesting(subid, group), reps, fill = list(mean_acc=0,
                                                    count=0))

47*2
## [1] 94
dim(dat)
## [1] 92  5
dat %>% filter(count < 6) 
## # A tibble: 8 x 5
##    subid   group   reps mean_acc count
##   <fctr>  <fctr> <fctr>    <dbl> <dbl>
## 1  ap105 control      4      0.0     2
## 2  ap116 control      2      0.5     2
## 3  ap116 control      4      1.0     1
## 4  ap119 control      4      0.6     5
## 5  ap160  stress      2      1.0     1
## 6  ap160  stress      4      0.0     0
## 7  ap169  stress      2      0.0     0
## 8  ap169  stress      4      0.0     2
# many low trial counts/bin!

rm_subids = dat %>% filter(count < 6) %>% pull(subid) %>% unique()
dat = dat %>% filter(!subid %in% rm_subids)

dat %>% group_by(subid, group) %>%summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    19
## 2  stress    22
dat = dat%>% mutate(mean_logit = car::logit(mean_acc))

contrasts(dat$reps) = c(-1,1); contrasts(dat$reps)
##   [,1]
## 2   -1
## 4    1
contrasts(dat$group) = c(1,-1); contrasts(dat$group)
##         [,1]
## control    1
## stress    -1
summary(lmer(mean_logit ~ group*reps + 
               (1|subid), data=dat)) # not enough obs for the RE
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: mean_logit ~ group * reps + (1 | subid)
##    Data: dat
## 
## REML criterion at convergence: 95.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.14047 -0.56911 -0.04094  0.64173  2.00488 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.0000   0.0000  
##  Residual             0.1597   0.3996  
## Number of obs: 82, groups:  subid, 41
## 
## Fixed effects:
##              Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)   0.16808    0.04424 78.00000   3.799 0.000286 ***
## group1        0.09690    0.04424 78.00000   2.190 0.031501 *  
## reps1         0.06391    0.04424 78.00000   1.445 0.152577    
## group1:reps1  0.03894    0.04424 78.00000   0.880 0.381439    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 reps1
## group1      0.073              
## reps1       0.000  0.000       
## group1:rps1 0.000  0.000  0.073

P(correct | “low conf old” to old item), broken down by shock condition

# just split by study reps
dat = dtest %>% 
  filter(subj_status == 'old', 
         reps > 0,
         conf == 'Lo') %>%
  group_by(subid, group, shockCond) %>%
  summarise(mean_acc = mean(acc_num), count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), shockCond, fill = list(mean_acc=0,
                                                         count=0))

dim(dat)
## [1] 92  5
dat %>% filter(count < 6) 
## # A tibble: 6 x 5
##    subid   group shockCond mean_acc count
##   <fctr>  <fctr>    <fctr>    <dbl> <dbl>
## 1  ap116 control      safe        0     1
## 2  ap116 control    threat        1     2
## 3  ap160  stress      safe        1     1
## 4  ap160  stress    threat        0     0
## 5  ap169  stress      safe        0     1
## 6  ap169  stress    threat        0     1
# many low trial counts/bin!

rm_subids = dat %>% filter(count < 6) %>% pull(subid) %>% unique()
dat = dat %>% filter(!subid %in% rm_subids)

dat %>% group_by(subid, group) %>%summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    21
## 2  stress    22
dat = dat%>% mutate(mean_logit = car::logit(mean_acc))

contrasts(dat$shockCond) = c(1,-1); contrasts(dat$shockCond)
##        [,1]
## safe      1
## threat   -1
contrasts(dat$group) = c(1,-1); contrasts(dat$group)
##         [,1]
## control    1
## stress    -1
summary(lmer(mean_acc ~ group*shockCond + 
               (1|subid), data=dat)) # not enough obs for the RE
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: mean_acc ~ group * shockCond + (1 | subid)
##    Data: dat
## 
## REML criterion at convergence: -115.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.58296 -0.52143  0.03298  0.61129  2.59950 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.00000  0.000   
##  Residual             0.01146  0.107   
## Number of obs: 86, groups:  subid, 43
## 
## Fixed effects:
##                   Estimate Std. Error       df t value Pr(>|t|)    
## (Intercept)        0.54464    0.01155 82.00000  47.171   <2e-16 ***
## group1             0.02533    0.01155 82.00000   2.194    0.031 *  
## shockCond1         0.01711    0.01155 82.00000   1.482    0.142    
## group1:shockCond1  0.01294    0.01155 82.00000   1.121    0.266    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 shckC1
## group1      0.023               
## shockCond1  0.000  0.000        
## grp1:shckC1 0.000  0.000  0.023
# what about just within stress
summary(lmer(mean_logit ~ shockCond + 
               (1|subid), data=dat %>% filter(group == 'stress'))) # not enough obs for the RE
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: mean_logit ~ shockCond + (1 | subid)
##    Data: dat %>% filter(group == "stress")
## 
## REML criterion at convergence: 44
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.74325 -0.45006 -0.07833  0.59734  1.93537 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 0.0000   0.0000  
##  Residual             0.1395   0.3734  
## Number of obs: 44, groups:  subid, 22
## 
## Fixed effects:
##             Estimate Std. Error       df t value Pr(>|t|)
## (Intercept)  0.07879    0.05630 42.00000   1.400    0.169
## shockCond1   0.01945    0.05630 42.00000   0.345    0.731
## 
## Correlation of Fixed Effects:
##            (Intr)
## shockCond1 0.000

S4) Localizer behavioral performance

P(correct)

##   X run trial   onset duration   cond subcond    resp acc respRT  subid
## 1 0   1     1 12.0068   1.4946 object manmade manmade   1 0.8153 loc100
## 2 1   1     2 13.9136   1.0869 object manmade manmade   1 0.8784 loc100
## 3 2   1     3 15.0290   1.4716 object natural natural   1 0.6792 loc100
## 4 3   1     4 16.5293   1.4712 object manmade manmade   1 0.6867 loc100
## 5 4   1     5 18.0304   1.4701 object natural natural   1 0.5906 loc100
## 6 5   1     6 19.5308   1.4700 object natural natural   1 0.3726 loc100
##     group duration_adj onset_adj
## 1 control       0.4946    0.0068
## 2 control       0.0869    1.9136
## 3 control       0.4716    3.0290
## 4 control       0.4712    4.5293
## 5 control       0.4701    6.0304
## 6 control       0.4700    7.5308
##         [,1]
## control    1
## stress    -1
##        [,1] [,2]
## face   -1.0  0.0
## object  0.5 -0.5
## place   0.5  0.5
## Analysis of Variance Table
##            Df Sum Sq Mean Sq F value
## group       1  2.334  2.3345  2.3345
## cond        2 59.612 29.8059 29.8059
## group:cond  2  4.068  2.0342  2.0342
## Generalized linear mixed model fit by maximum likelihood (Laplace
##   Approximation) [glmerMod]
##  Family: binomial  ( logit )
## Formula: acc ~ group * cond + (1 + cond | subid)
##    Data: dl_acc
## 
##      AIC      BIC   logLik deviance df.resid 
##  10789.5  10877.5  -5382.8  10765.5    11268 
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -4.2853  0.2733  0.4201  0.5289  1.0637 
## 
## Random effects:
##  Groups Name        Variance Std.Dev. Corr       
##  subid  (Intercept) 0.38674  0.6219              
##         cond1       0.01704  0.1305    0.37      
##         cond2       0.04018  0.2004   -0.32 -0.75
## Number of obs: 11280, groups:  subid, 47
## 
## Fixed effects:
##              Estimate Std. Error z value Pr(>|z|)    
## (Intercept)   1.49874    0.09451  15.857  < 2e-16 ***
## group1        0.14208    0.09437   1.506    0.132    
## cond1        -0.28942    0.04317  -6.704 2.02e-11 ***
## cond2        -0.09023    0.06788  -1.329    0.184    
## group1:cond1  0.05731    0.04110   1.394    0.163    
## group1:cond2  0.07734    0.06496   1.190    0.234    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1  cond2  grp1:1
## group1       0.028                            
## cond1        0.126  0.006                     
## cond2       -0.142  0.001 -0.162              
## group1:cnd1  0.004  0.138  0.068  0.003       
## group1:cnd2  0.000 -0.146  0.004  0.085 -0.176

Median RT for correct responses

## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    23
## 2  stress    24
##         [,1]
## control    1
## stress    -1
##        [,1] [,2]
## face   -1.0  0.0
## object  0.5 -0.5
## place   0.5  0.5
## Analysis of Variance Table of type III  with  Satterthwaite 
## approximation for degrees of freedom
##              Sum Sq  Mean Sq NumDF  DenDF F.value  Pr(>F)    
## group      0.002166 0.002166     1 45.000   3.784 0.05799 .  
## cond       0.112059 0.056029     2 90.002  97.887 < 2e-16 ***
## group:cond 0.001425 0.000713     2 90.002   1.245 0.29290    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: respRT ~ group * cond + (1 | subid)
##    Data: dl_med
## 
## REML criterion at convergence: -417.9
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.40203 -0.52180 -0.03465  0.48143  2.08678 
## 
## Random effects:
##  Groups   Name        Variance  Std.Dev.
##  subid    (Intercept) 0.0107372 0.10362 
##  Residual             0.0005724 0.02392 
## Number of obs: 141, groups:  subid, 47
## 
## Fixed effects:
##               Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)   0.540788   0.015252 45.000000  35.457   <2e-16 ***
## group1        0.029670   0.015252 45.000000   1.945   0.0580 .  
## cond1         0.039558   0.002850 90.000000  13.880   <2e-16 ***
## cond2         0.008724   0.004936 90.000000   1.767   0.0806 .  
## group1:cond1  0.003524   0.002850 90.000000   1.236   0.2195    
## group1:cond2  0.004839   0.004936 90.000000   0.980   0.3296    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1 cond2 grp1:1
## group1      0.021                           
## cond1       0.000  0.000                    
## cond2       0.000  0.000  0.000             
## group1:cnd1 0.000  0.000  0.021 0.000       
## group1:cnd2 0.000  0.000  0.000 0.021 0.000

S5) Motion

Motion @retrieval (when stressor present)

dmot = read.csv('/Volumes/group/awagner/sgagnon/AP/results/group_motion.csv')
str(dmot)
## 'data.frame':    71808 obs. of  13 variables:
##  $ X           : int  0 1 2 3 4 5 6 7 8 9 ...
##  $ tr          : int  0 1 2 3 4 5 6 7 8 9 ...
##  $ rot_x       : num  -4.06e-04 -4.78e-04 -4.78e-04 -2.68e-06 5.10e-05 ...
##  $ rot_y       : num  0.00171 0.00192 0.00182 0.00173 0.00144 ...
##  $ rot_z       : num  0.000213 0.000476 0.000296 0 0.000215 ...
##  $ trans_x     : num  0.0538 0.0537 0.0538 0.0538 0.0538 ...
##  $ trans_y     : num  -3.89e-05 4.74e-03 -5.50e-05 -7.32e-03 -1.96e-05 ...
##  $ trans_z     : num  0.000196 0.019579 0.022204 0.038783 0.044569 ...
##  $ displace_abs: num  0.103 0.117 0.112 0.112 0.103 ...
##  $ displace_rel: num  0 0.0269 0.0116 0.0345 0.0203 ...
##  $ subid       : Factor w/ 44 levels "ap100","ap101",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ run         : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ group       : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
# Retrieval TRs:
d = dmot %>% filter(!subid %in% c('ap151', 'ap156'),
                  run %in% c(1,2,3,4,5,6)) %>%
  group_by(subid, group) %>%
  summarise(max_displ = max(displace_rel), 
            med_displ = median(displace_rel), 
            n=n())

d %>% group_by(group) %>% summarise(n(), mean(max_displ), sd(max_displ), 
                                    mean(med_displ), sd(med_displ))
## # A tibble: 2 x 6
##     group `n()` `mean(max_displ)` `sd(max_displ)` `mean(med_displ)`
##    <fctr> <int>             <dbl>           <dbl>             <dbl>
## 1 control    22         0.4492777       0.4889915        0.03490903
## 2  stress    22         0.7557733       0.7217924        0.03705162
## # ... with 1 more variables: `sd(med_displ)` <dbl>
bartlett.test(max_displ ~ group, data=d)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  max_displ by group
## Bartlett's K-squared = 3.0345, df = 1, p-value = 0.08151
t.test(max_displ ~ group, data=d, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  max_displ by group
## t = -1.6489, df = 42, p-value = 0.1066
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.68160841  0.06861723
## sample estimates:
## mean in group control  mean in group stress 
##             0.4492777             0.7557733
with(d, boxplot(max_displ ~ group))

with(d, boxplot(max_displ))

bartlett.test(med_displ ~ group, data=d)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  med_displ by group
## Bartlett's K-squared = 2.7637, df = 1, p-value = 0.09642
t.test(med_displ ~ group, data=d, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  med_displ by group
## t = -0.66925, df = 42, p-value = 0.507
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.008603469  0.004318273
## sample estimates:
## mean in group control  mean in group stress 
##            0.03490903            0.03705162
with(d, boxplot(med_displ ~ group))

with(d, boxplot(med_displ))

dmot %>% filter(displace_rel > 2)
##       X  tr        rot_x        rot_y      rot_z    trans_x   trans_y
## 1 32361  20 -0.005064260 -0.000988498 -0.0044876 -0.0830918  0.510269
## 2 40116 218  0.000678324 -0.002894750 -0.0113798  0.5412270 -0.192115
##    trans_z displace_abs displace_rel subid run   group
## 1 0.138049     0.682681      2.46140 ap121   6 control
## 2 1.835810     2.009170      3.33342 ap154   3  stress

Motion @localizer

d = dmot %>% filter(!subid %in% c('ap151', 'ap156'),
                  run %in% c(7,8)) %>%
  group_by(subid, group) %>%
  summarise(max_displ = max(displace_rel), 
            med_displ = median(displace_rel), n=n())

d %>% group_by(group) %>% summarise(n(), mean(max_displ), mean(med_displ),
                                    sd(max_displ), sd(med_displ))
## # A tibble: 2 x 6
##     group `n()` `mean(max_displ)` `mean(med_displ)` `sd(max_displ)`
##    <fctr> <int>             <dbl>             <dbl>           <dbl>
## 1 control    22         0.3324237        0.03268982       0.2681085
## 2  stress    22         0.4006318        0.03414530       0.2582950
## # ... with 1 more variables: `sd(med_displ)` <dbl>
bartlett.test(max_displ ~ group, data=d)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  max_displ by group
## Bartlett's K-squared = 0.028515, df = 1, p-value = 0.8659
t.test(max_displ ~ group, data=d, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  max_displ by group
## t = -0.85935, df = 42, p-value = 0.395
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.22838755  0.09197127
## sample estimates:
## mean in group control  mean in group stress 
##             0.3324237             0.4006318
bartlett.test(med_displ ~ group, data=d)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  med_displ by group
## Bartlett's K-squared = 0.36234, df = 1, p-value = 0.5472
t.test(med_displ ~ group, data=d, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  med_displ by group
## t = -0.54606, df = 42, p-value = 0.5879
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.006834574  0.003923610
## sample estimates:
## mean in group control  mean in group stress 
##            0.03268982            0.03414530

S6) Other ROI Analyses

basedir = '/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/'

dt = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/mvpa/notebooks/ap_behav.csv')
head(dt)
##   X run trial   onset duration shockCond shockTrial  target      associate
## 1 0   1     1 12.0191  10.6661      safe          0  BANDIT       cemetery
## 2 1   1     2 22.7129   9.1242      safe          0  WALRUS           foil
## 3 2   1     3 31.8642   9.4224      safe          0  VIOLIN    throne_room
## 4 3   1     4 41.3132  11.3389      safe          0   MEDAL       hayfield
## 5 4   1     5 52.6786   9.7644      safe          0  MANURE         canyon
## 6 5   1     6 62.4701   9.1180      safe          0 SARDINE mountain_snowy
##      resp acc accSpec respRT subid        group remove anxious happy safe
## 1  indoor  SM  SMO_Hi 2.1094 ap100 control-fmri     NA       3     2    3
## 2    foil  CR      CR 1.7773 ap100 control-fmri     NA       3     2    3
## 3  indoor   H   HI_Hi 1.6804 ap100 control-fmri     NA       3     2    3
## 4 outdoor   H   HO_Hi 1.7268 ap100 control-fmri     NA       3     2    3
## 5 outdoor   H   HO_Hi 1.3734 ap100 control-fmri     NA       3     2    3
## 6 outdoor   H   HO_Hi 2.1476 ap100 control-fmri     NA       3     2    3
##   stressed life_stress sleep cond_orig    cond reps shock_and_post conf
## 1        3           4   4.5      TO_4 outdoor    4              0   Hi
## 2        3           4   4.5       F_0    foil    0              0    N
## 3        3           4   4.5      TI_2  indoor    2              0   Hi
## 4        3           4   4.5      TO_2 outdoor    2              0   Hi
## 5        3           4   4.5      TO_2 outdoor    2              0   Hi
## 6        3           4   4.5      TO_4 outdoor    4              0   Hi
##   onset_adj mem_conditions obj_conditions onset_code        rt_z
## 1    0.0191  sourcemiss_hi            old    itemhit -1.20388009
## 2   10.7129             CR            new         CR -0.12867526
## 3   19.8642      sourcehit            old  sourcehit -0.74601988
## 4   29.3132      sourcehit            old  sourcehit -0.67385952
## 5   40.6786      sourcehit            old  sourcehit -1.22346016
## 6   50.4701      sourcehit            old  sourcehit -0.01943975
##   mem_conditions_byrep onset_code_byrep
## 1      sourcemiss_hi-4        itemhit-4
## 2                 CR-0             CR-0
## 3          sourcehit-2      sourcehit-2
## 4          sourcehit-2      sourcehit-2
## 5          sourcehit-2      sourcehit-2
## 6          sourcehit-4      sourcehit-4
counts = dt %>%
  group_by(subid, mem_conditions) %>%
  summarise(n=n()) %>%
  ungroup() %>%
  complete(subid, mem_conditions, fill = list(n=0)) %>%
  filter(!mem_conditions %in% c('nuisance', 'FA', 'M'))
# length(unique(dt$mem_conditions)) * length(unique(dt$subid))

counts %>% filter(n <= 5)
## # A tibble: 9 x 3
##    subid mem_conditions     n
##   <fctr>         <fctr> <dbl>
## 1  ap104     itemhit_lo     0
## 2  ap110  sourcemiss_hi     1
## 3  ap116     itemhit_lo     3
## 4  ap151      sourcehit     3
## 5  ap151  sourcemiss_hi     2
## 6  ap156      sourcehit     5
## 7  ap158  sourcemiss_hi     3
## 8  ap160     itemhit_lo     1
## 9  ap169     itemhit_lo     2

Hippocampus

## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
## 'data.frame':    1584 obs. of  10 variables:
##  $ X        : int  2 3 31 32 60 61 89 90 118 119 ...
##  $ cond     : Factor w/ 6 levels "CR","FA","itemhit_lo",..: 1 1 2 2 5 5 3 3 6 6 ...
##  $ hemi     : Factor w/ 2 levels "lh","rh": 1 2 1 2 1 2 1 2 1 2 ...
##  $ mask_vox : num  69 54 69 54 69 54 69 54 69 54 ...
##  $ regspace : Factor w/ 1 level "epi": 1 1 1 1 1 1 1 1 1 1 ...
##  $ roi      : chr  "hippocampus-head" "hippocampus-head" "hippocampus-head" "hippocampus-head" ...
##  $ smoothing: Factor w/ 1 level "unsmoothed": 1 1 1 1 1 1 1 1 1 1 ...
##  $ subid    : Factor w/ 44 levels "ap100","ap101",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ value    : num  -161 -443 -130 -458 125 ...
##  $ group    : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
## # A tibble: 6 x 6
##    subid   group      cond              roi      value roi_num
##   <fctr>  <fctr>    <fctr>           <fctr>      <dbl>   <dbl>
## 1  ap100 control        CR hippocampus-body -996.64670       0
## 2  ap100 control        CR hippocampus-head -301.80224      -1
## 3  ap100 control        CR hippocampus-tail -339.09103       1
## 4  ap100 control sourcehit hippocampus-body  -97.46697       0
## 5  ap100 control sourcehit hippocampus-head  120.20124      -1
## 6  ap100 control sourcehit hippocampus-tail  361.57621       1
##         [,1]
## control    1
## stress    -1
##           [,1]
## CR          -1
## sourcehit    1
## refitting model(s) with ML (instead of REML)
## Data: data
## Models:
## object: value ~ group * cond * scale(roi_num) + (1 + cond + scale(roi_num) | 
## object:     subid)
## ..1: value ~ group * cond * poly(roi_num, degree = 2) + (1 + cond + 
## ..1:     poly(roi_num, degree = 2) | subid)
##        Df    AIC    BIC  logLik deviance  Chisq Chi Df Pr(>Chisq)    
## object 15 3784.2 3837.8 -1877.1   3754.2                             
## ..1    23 3714.4 3796.6 -1834.2   3668.4 85.799      8  3.303e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond * poly(roi_num, degree = 2) + (1 + cond +  
##     poly(roi_num, degree = 2) | subid)
##    Data: data
## Control: lmerControl(optimizer = "bobyqa", optCtrl = list(maxfun = 2e+05))
## 
## REML criterion at convergence: 3535.6
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7587 -0.3561 -0.0463  0.3866  4.0278 
## 
## Random effects:
##  Groups   Name                       Variance Std.Dev. Corr             
##  subid    (Intercept)                  61011   247.0                    
##           cond1                        27983   167.3   -0.26            
##           poly(roi_num, degree = 2)1 4091283  2022.7    0.07  0.10      
##           poly(roi_num, degree = 2)2  789382   888.5   -0.18  0.20 -0.05
##  Residual                              18199   134.9                    
## Number of obs: 264, groups:  subid, 44
## 
## Fixed effects:
##                                         Estimate Std. Error       df
## (Intercept)                               22.317     38.152   42.000
## group1                                     7.291     38.152   42.000
## cond1                                    213.737     26.550   42.000
## poly(roi_num, degree = 2)1              1715.127    333.441   42.000
## poly(roi_num, degree = 2)2              1537.733    190.105   42.000
## group1:cond1                              39.711     26.550   42.000
## group1:poly(roi_num, degree = 2)1        808.336    333.441   42.000
## group1:poly(roi_num, degree = 2)2        -15.040    190.105   42.000
## cond1:poly(roi_num, degree = 2)1         291.992    134.905   84.220
## cond1:poly(roi_num, degree = 2)2        -240.093    134.905   84.220
## group1:cond1:poly(roi_num, degree = 2)1  290.724    134.905   84.220
## group1:cond1:poly(roi_num, degree = 2)2  -29.255    134.905   84.220
##                                         t value Pr(>|t|)    
## (Intercept)                               0.585   0.5617    
## group1                                    0.191   0.8494    
## cond1                                     8.050 4.76e-10 ***
## poly(roi_num, degree = 2)1                5.144 6.67e-06 ***
## poly(roi_num, degree = 2)2                8.089 4.21e-10 ***
## group1:cond1                              1.496   0.1422    
## group1:poly(roi_num, degree = 2)1         2.424   0.0197 *  
## group1:poly(roi_num, degree = 2)2        -0.079   0.9373    
## cond1:poly(roi_num, degree = 2)1          2.164   0.0333 *  
## cond1:poly(roi_num, degree = 2)2         -1.780   0.0787 .  
## group1:cond1:poly(roi_num, degree = 2)1   2.155   0.0340 *  
## group1:cond1:poly(roi_num, degree = 2)2  -0.217   0.8288    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##               (Intr) group1 cond1  p(_,d=2)1 p(_,d=2)2 grp1:1 g1:(_,d=2)1
## group1         0.000                                                     
## cond1         -0.238  0.000                                              
## ply(_,d=2)1    0.065  0.000  0.089                                       
## ply(_,d=2)2   -0.122  0.000  0.132 -0.034                                
## group1:cnd1    0.000 -0.238  0.000  0.000     0.000                      
## g1:(_,d=2)1    0.000  0.065  0.000  0.000     0.000     0.089            
## g1:(_,d=2)2    0.000 -0.122  0.000  0.000     0.000     0.132 -0.034     
## c1:(_,d=2)1    0.000  0.000  0.000  0.000     0.000     0.000  0.000     
## c1:(_,d=2)2    0.000  0.000  0.000  0.000     0.000     0.000  0.000     
## g1:1:(_,d=2)1  0.000  0.000  0.000  0.000     0.000     0.000  0.000     
## g1:1:(_,d=2)2  0.000  0.000  0.000  0.000     0.000     0.000  0.000     
##               g1:(_,d=2)2 c1:(_,d=2)1 c1:(_,d=2)2 g1:1:(_,d=2)1
## group1                                                         
## cond1                                                          
## ply(_,d=2)1                                                    
## ply(_,d=2)2                                                    
## group1:cnd1                                                    
## g1:(_,d=2)1                                                    
## g1:(_,d=2)2                                                    
## c1:(_,d=2)1    0.000                                           
## c1:(_,d=2)2    0.000       0.000                               
## g1:1:(_,d=2)1  0.000       0.000       0.000                   
## g1:1:(_,d=2)2  0.000       0.000       0.000       0.000
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond + (1 | subid)
##    Data: data %>% filter(roi == "hippocampus-tail")
## 
## REML criterion at convergence: 1233.6
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.54376 -0.55680  0.06163  0.52651  2.77698 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 63192    251.4   
##  Residual             66186    257.3   
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##              Estimate Std. Error     df t value Pr(>|t|)    
## (Intercept)    218.52      46.78  42.00   4.671 3.07e-05 ***
## group1          67.57      46.78  42.00   1.444   0.1560    
## cond1          225.30      27.42  41.15   8.215 3.27e-10 ***
## group1:cond1    60.35      27.42  41.15   2.201   0.0334 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1
## group1      0.000              
## cond1       0.000  0.000       
## group1:cnd1 0.000  0.000  0.000
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond + (1 | subid)
##    Data: data %>% filter(roi == "hippocampus-body")
## 
## REML criterion at convergence: 1234.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -1.9561 -0.5522  0.0979  0.5709  3.1301 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 43827    209.3   
##  Residual             78113    279.5   
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##              Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)   -111.53      43.40   42.00  -2.570   0.0138 *  
## group1           8.60      43.40   42.00   0.198   0.8439    
## cond1          234.63      29.79   42.36   7.875 7.88e-10 ***
## group1:cond1    42.26      29.79   42.36   1.418   0.1634    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1
## group1      0.000              
## cond1       0.000  0.000       
## group1:cnd1 0.000  0.000  0.000
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond + (1 | subid)
##    Data: data %>% filter(roi == "hippocampus-head")
## 
## REML criterion at convergence: 1236.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.4889 -0.4274  0.0823  0.4528  3.1842 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 47527    218.0   
##  Residual             78198    279.6   
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##              Estimate Std. Error     df t value Pr(>|t|)    
## (Intercept)    -40.04      44.37  42.00  -0.902    0.372    
## group1         -54.29      44.37  42.00  -1.224    0.228    
## cond1          181.28      29.81  42.01   6.081 3.03e-07 ***
## group1:cond1    16.52      29.81  42.01   0.554    0.582    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1
## group1      0.000              
## cond1       0.000  0.000       
## group1:cnd1 0.000  0.000  0.000
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean by group
## Bartlett's K-squared = 0.61163, df = 1, p-value = 0.4342
## 
##  Two Sample t-test
## 
## data:  mean by group
## t = 2.4099, df = 42, p-value = 0.02042
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##   41.5969 470.0802
## sample estimates:
## mean in group control  mean in group stress 
##              571.7385              315.9000
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean by group
## Bartlett's K-squared = 1.5672, df = 1, p-value = 0.2106
## 
##  Two Sample t-test
## 
## data:  mean by group
## t = 1.0997, df = 42, p-value = 0.2777
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -84.93655 288.36693
## sample estimates:
## mean in group control  mean in group stress 
##             173.96692              72.25173
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean by group
## Bartlett's K-squared = 2.9085, df = 1, p-value = 0.08811
## 
##  Two Sample t-test
## 
## data:  mean by group
## t = -0.76208, df = 42, p-value = 0.4503
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -275.5819  124.5010
## sample estimates:
## mean in group control  mean in group stress 
##              103.4644              179.0048

Angular

sub_remove = counts %>% 
  filter(mem_conditions %in% c('sourcehit', 'CR'), 
         n <= 5) %>% 
  pull(subid); sub_remove
## [1] ap151 ap156
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
basedir = '/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/'
d2 = read.csv(paste(basedir,'pe_DefaultA_IPL.csv', sep=''))
data = d2 %>%
  filter(cond %in% c('sourcehit', 'CR'))
# dim(data)
data = data %>% filter(!(subid %in% sub_remove))
# dim(data)

contrasts(data$group) = c(1, -1); contrasts(data$group)
##         [,1]
## control    1
## stress    -1
data$cond = factor(data$cond)
contrasts(data$cond) = c(-1,1); contrasts(data$cond)
##           [,1]
## CR          -1
## sourcehit    1
summary(lmer(value ~ group * cond + (1|subid), data=data)) # including cond RE not enough obs
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond + (1 | subid)
##    Data: data
## 
## REML criterion at convergence: 1397.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.1244 -0.6417 -0.1722  0.7609  2.2033 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept)  93644   306.0   
##  Residual             702538   838.2   
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##              Estimate Std. Error      df t value Pr(>|t|)    
## (Intercept)   -812.37     100.56   42.00  -8.079 4.34e-10 ***
## group1        -219.41     100.56   42.00  -2.182   0.0348 *  
## cond1          642.48      89.35   37.87   7.191 1.39e-08 ***
## group1:cond1    98.85      89.35   37.87   1.106   0.2755    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1
## group1      0.000              
## cond1       0.000  0.000       
## group1:cnd1 0.000  0.000  0.000

Retrosplenial

basedir = '/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/'
d2 = read.csv(paste(basedir,'pe_DefaultC_Rsp.csv', sep=''))
data = d2 %>%
  filter(cond %in% c('sourcehit', 'CR')) %>%
  group_by(subid, group, cond) %>%
  summarise(value = mean(value))
# dim(data)
data = data %>% filter(!(subid %in% sub_remove))
# dim(data)

contrasts(data$group) = c(1, -1); contrasts(data$group)
##         [,1]
## control    1
## stress    -1
data$cond = factor(data$cond)
contrasts(data$cond) = c(-1,1); contrasts(data$cond)
##           [,1]
## CR          -1
## sourcehit    1
summary(lmer(value ~ group * cond + (1|subid), data=data)) # including cond RE not enough obs
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: value ~ group * cond + (1 | subid)
##    Data: data
## 
## REML criterion at convergence: 1378.2
## 
## Scaled residuals: 
##      Min       1Q   Median       3Q      Max 
## -2.37663 -0.46248  0.02745  0.57687  1.59530 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  subid    (Intercept) 246313   496.3   
##  Residual             431854   657.2   
## Number of obs: 88, groups:  subid, 44
## 
## Fixed effects:
##              Estimate Std. Error     df t value Pr(>|t|)    
## (Intercept)    215.40     102.50  42.00   2.102   0.0416 *  
## group1          42.07     102.50  42.00   0.410   0.6836    
## cond1          910.64      70.05  41.46  12.999 4.44e-16 ***
## group1:cond1    79.84      70.05  41.46   1.140   0.2609    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) group1 cond1
## group1      0.000              
## cond1       0.000  0.000       
## group1:cnd1 0.000  0.000  0.000

S7) Reinstatement

VTC equalize trial counts

d = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_bilat-parahipp_fusi_inftemp_allcat_byreps_avg_46810_filtartloc_equalizetrials.csv')
dt = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/mvpa/notebooks/ap_behav.csv')

subids_rm = c('ap168', 'ap174')
with(d %>% filter(category == 'place'), table(subid, condition))
##        condition
## subid   CR sourcehit
##   ap100 60        62
##   ap101 82        79
##   ap102 23        21
##   ap103 74        72
##   ap104 75        81
##   ap105 71        72
##   ap107 50        50
##   ap108 27        26
##   ap109 38        38
##   ap110 19        20
##   ap111 57        59
##   ap113 57        59
##   ap114 49        50
##   ap115 52        56
##   ap116 75        72
##   ap117 67        67
##   ap118 36        36
##   ap119 78        78
##   ap120 61        62
##   ap121  7         7
##   ap122 34        33
##   ap150 35        35
##   ap152 41        40
##   ap153 32        31
##   ap154 42        39
##   ap155 22        22
##   ap157 40        40
##   ap158 11        11
##   ap159 50        49
##   ap160 43        43
##   ap161 27        27
##   ap162 19        19
##   ap163 74        74
##   ap164 10        12
##   ap165 49        53
##   ap166 57        58
##   ap167 32        34
##   ap168 35        35
##   ap169 63        64
##   ap170 55        55
##   ap171 32        32
##   ap172 19        19
##   ap173  8         8
##   ap174 56        57
d = d %>%
  filter(!subid %in% subids_rm,
         category == 'place', 
         condition == 'sourcehit')
dim(d)
## [1] 1865   16
head(d)
##    X index   group subid run    onset condition category        X0
## 1  5     5 control ap100   1  29.3132 sourcehit    place  5.668776
## 2 17    17 control ap100   1 137.3692 sourcehit    place  2.171703
## 3 20    20 control ap100   1 147.7725 sourcehit    place  3.724785
## 4 26    26 control ap100   1 189.8279 sourcehit    place -2.201856
## 5 29    29 control ap100   1 199.3947 sourcehit    place -6.341303
## 6 32    32 control ap100   1 249.7552 sourcehit    place  4.799252
##           X2         X4         X6         X8        X10       X12
## 1  7.0095601  3.2375235 -3.2345678 -1.3963429  8.6132175 10.457438
## 2  7.4833026  5.3206003  0.2201440  2.8257519  5.2779771 -1.238594
## 3 -0.3012936 -0.8840364  5.8113141  5.8149256 -3.7053775 -7.765064
## 4 -2.6881330  7.6396394  9.2119951 -1.0437411 -5.2589488 -1.989815
## 5 -1.0425030  4.3576636  4.6364212 -0.2640133 -5.1733994 -3.861562
## 6 14.6948134  8.0496648 -0.2553808 -2.2946936  0.5734839  2.898207
##   avg_logit
## 1  1.804958
## 2  3.411118
## 3  1.759206
## 4  2.637236
## 5  0.889168
## 6  1.518269
dj = dt %>%
  mutate(onset=onset_adj, img_type=cond) %>% 
  dplyr::select(-group, -reps, -cond) %>%
  right_join(d, by=c('subid', 'run', 'onset')) %>%
  mutate(subid = factor(subid), imgType = factor(img_type))
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
# str(dj)

dim(dj)
## [1] 1865   46
dt %>% filter(shock_and_post != 0)
##         X run trial    onset duration shockCond shockTrial     target
## 1    4308   1    38 388.8635  13.2663    threat          1     WALLET
## 2    4309   1    39 402.5077   8.7762    threat          0       WINE
## 3    4387   3    33 332.6727  13.3357    threat          1     SHRIMP
## 4    4388   3    34 346.0418   9.7581    threat          0        FAN
## 5    4443   5     5  52.4561  12.9926    threat          1     OMELET
## 6    4444   5     6  65.4843   9.5305    threat          0       SOUP
## 7    4465   5    27 280.4064  13.6152    threat          1     CAMERA
## 8    4466   5    28 294.0577   9.3696    threat          0       VINE
## 9    4580   2    16 162.8869  11.3899    threat          1       DOLL
## 10   4581   2    17 174.3062   9.9225    threat          0       ROSE
## 11   4666   4    18 188.7935  11.7510    threat          1      TOAST
## 12   4667   4    19 200.9294   8.7454    threat          0       HOOK
## 13   4753   6    21 219.7744  12.5499    threat          1        ANT
## 14   4754   6    22 232.3590  12.3240    threat          0     MONKEY
## 15   4760   6    28 294.0528  11.1433    threat          1      FENCE
## 16   4761   6    29 305.2337   9.6254    threat          0    HIGHWAY
## 17   4781   1     7  69.5282  14.3258    threat          1    LANTERN
## 18   4782   1     8  84.2717   8.9864    threat          0       BABY
## 19   4891   3    33 337.3948  11.9207    threat          1     SPONGE
## 20   4892   3    34 349.3487   9.7522    threat          0        FAN
## 21   4950   5     8  81.0813  11.1761    threat          1      RIFLE
## 22   4951   5     9  92.2900   9.9096    threat          0     CANDLE
## 23   4964   5    22 228.0153  11.6811    threat          1     PYTHON
## 24   4965   5    23 239.7295   9.0981    threat          0   SCORPION
## 25   5103   2    35 358.2914  11.2510    threat          1     ROSARY
## 26   5104   2    36 369.5712  10.5693    threat          0     SCROLL
## 27   5166   4    14 145.5132  11.6300    threat          1      QUAIL
## 28   5167   4    15 157.2813  10.4610    threat          0      TEETH
## 29   5237   6     1  12.0050  12.4959    threat          1     SPONGE
## 30   5238   6     2  24.5388   9.0512    threat          0     TROPHY
## 31   5245   6     9  93.6401  11.7989    threat          1     ORANGE
## 32   5246   6    10 105.4761  10.9878    threat          0     RUDDER
## 33   5297   1    19 194.7396  11.8971    threat          1       HOOK
## 34   5298   1    20 206.7664  11.2363    threat          0     ZIPPER
## 35   5365   3     3  30.7302  11.3891    threat          1      QUILL
## 36   5366   3     4  42.1530   9.2489    threat          0     MITTEN
## 37   5449   5     3  34.1849  11.9280    threat          1        MAP
## 38   5450   5     4  46.1465   9.6823    threat          0        KEG
## 39   5482   5    36 374.1904  12.6467    threat          1   SCISSORS
## 40   5483   5    37 386.8735   9.1087    threat          0        HAM
## 41   5610   2    38 389.7051  12.4671    threat          1      PIANO
## 42   5611   2    39 402.2028  10.9949    threat          0       RAKE
## 43   5687   4    31 315.3568  11.9062    threat          1    ASPIRIN
## 44   5688   4    32 327.2968  10.0916    threat          0      APPLE
## 45   5773   1    33 339.4238  11.0549    threat          1      PIANO
## 46   5774   1    34 350.5082   9.4189    threat          0    STAPLER
## 47   5855   3    31 316.0909  13.2648    threat          1      BIBLE
## 48   5856   3    32 329.4975   9.5201    threat          0        FAN
## 49   5922   5    14 139.8456  13.3316    threat          1      BRAIN
## 50   5923   5    15 153.2127   9.1405    threat          0      OPIUM
## 51   5924   5    16 162.3878  13.2619    threat          1     FIDDLE
## 52   5925   5    17 175.6882  12.3158    threat          0    HIGHWAY
## 53   6062   2    28 288.3530  12.5493    threat          1    GARBAGE
## 54   6063   2    29 301.2897  11.3239    threat          0       FORK
## 55   6143   4    25 254.2745  14.3201    threat          1     RABBIT
## 56   6144   4    26 268.6304  10.1910    threat          0       WINE
## 57   6211   6     9  93.2720  12.7042    threat          1       CLAM
## 58   6212   6    10 106.0143   9.8862    threat          0      EASEL
## 59   6240   6    38 388.5212  12.0980    threat          1      TOAST
## 60   6241   6    39 400.6577  10.1893    threat          0   SCORPION
## 61   6311   2    25 263.0002  12.1957    threat          1      QUAIL
## 62   6312   2    26 275.2265   9.3894    threat          0   TWEEZERS
## 63   6405   4    35 361.1516  13.6753    threat          1    SARDINE
## 64   6406   4    36 374.8610   9.9290    threat          0      GEESE
## 65   6474   6    20 208.5525  12.3666    threat          1      PEARL
## 66   6475   6    21 220.9555   9.8877    threat          0    JUGGLER
## 67   6492   6    38 395.3022  11.3682    threat          1     POSTER
## 68   6493   6    39 406.7067   9.1399    threat          0     ROSARY
## 69   6515   1    19 197.5353  13.2642    threat          1     MANURE
## 70   6516   1    20 210.8293   9.3761    threat          0       GOAT
## 71   6536   1    40 413.6314  11.0594    threat          1        NET
## 72   6537   1    41 424.8264  10.3646    threat          0      CORAL
## 73   6596   3    16 168.0995  11.6279    threat          1     MONKEY
## 74   6597   3    17 179.7602   9.9870    threat          0       ROSE
## 75   6676   5    12 129.1745  12.1020    threat          1    RACQUET
## 76   6677   5    13 141.3117  11.5306    threat          1       WHIP
## 77   6678   5    14 152.8769   9.9073    threat          0     PUDDLE
## 78   6809   2    19 195.2545  14.3221    threat          1   TWEEZERS
## 79   6810   2    20 209.6069   9.7612    threat          0      GEESE
## 80   6901   4    27 275.6425  11.6810    threat          1     CARROT
## 81   6902   4    28 287.4599  12.2185    threat          0        ANT
## 82   6966   6     8  83.6481  11.4126    threat          1     NOODLE
## 83   6967   6     9  95.0966  10.9899    threat          0    LETTUCE
## 84   6972   6    14 143.4211  11.9064    threat          1      SHEEP
## 85   6973   6    15 155.3631  10.1932    threat          0       LION
## 86   7032   1    32 329.2043  11.4189    threat          1    SPATULA
## 87   7033   1    33 340.7563   9.1498    threat          0     ORCHID
## 88   7115   3    31 316.7444  11.1134    threat          1       BOAT
## 89   7116   3    32 327.8903  12.3220    threat          0  SAXOPHONE
## 90   7172   5     4  42.1248  11.9183    threat          1    HARPOON
## 91   7173   5     5  54.0802   9.1177    threat          0     PYTHON
## 92   7199   5    31 318.8659  11.1393    threat          1    LANTERN
## 93   7200   5    32 330.0435   9.0496    threat          0     ICICLE
## 94   7311   2    17 176.4960  13.3340    threat          1       DOVE
## 95   7312   2    18 189.8603   9.1013    threat          0    SARDINE
## 96   7402   4    24 252.1435  12.6475    threat          1    SLIPPER
## 97   7403   4    25 264.9348   9.8093    threat          0       PLUG
## 98   7466   6     4  43.3746  12.5480    threat          1      PIANO
## 99   7467   6     5  55.9605   9.6796    threat          0     BARREL
## 100  7492   6    30 316.6024  12.1877    threat          1    RACQUET
## 101  7493   6    31 328.8293   9.1158    threat          0     TROPHY
## 102  7550   2     4  43.1248  12.0943    threat          1     WALLET
## 103  7551   2     5  55.2492   9.8056    threat          0       BOAT
## 104  7636   4     6  60.3592  11.9181    threat          1     TURTLE
## 105  7637   4     7  72.6665   9.0304    threat          0     CARROT
## 106  7732   6    18 183.3171  13.1799    threat          1     BARREL
## 107  7733   6    19 196.5336  10.9880    threat          0      CLOAK
## 108  7743   6    29 300.6094  11.7544    threat          1      BENCH
## 109  7744   6    30 312.4025  10.4626    threat          0      GEESE
## 110  7784   1    28 286.1872  11.6897    threat          1        ANT
## 111  7785   1    29 297.9053   9.0583    threat          0      TRIBE
## 112  7850   3    10 100.1384  11.0979    threat          1       WORM
## 113  7851   3    11 111.6157   9.2843    threat          0       KILT
## 114  7934   5    10 106.2110  12.7053    threat          1      WHEAT
## 115  7935   5    11 118.9534   9.1085    threat          0   ENVELOPE
## 116  7965   5    41 420.2549  14.3217    threat          1      SALAD
## 117  7966   5    42 434.6141   9.7532    threat          0       RICE
## 118  8059   2     9  92.6728  11.6839    threat          1    STOMACH
## 119  8060   2    10 104.3876  10.0960    threat          0     WALLET
## 120  8141   4     7  75.6126  12.3677    threat          1     NEEDLE
## 121  8142   4     8  88.0141  10.1931    threat          0    PUMPKIN
## 122  8236   6    18 192.0202  13.1773    threat          1       BOWL
## 123  8237   6    19 205.2341   9.2689    threat          0      PEARL
## 124  8247   6    29 303.3809  12.1005    threat          1     TROPHY
## 125  8248   6    30 315.5210   9.0480    threat          0        HAM
## 126  9566   2     4  44.0804  12.6507    threat          1        KEG
## 127  9567   2     5  56.7611  12.3272    threat          0       LION
## 128  9658   4    12 125.3795  13.3322    threat          1  CHOCOLATE
## 129  9659   4    13 138.8557   9.8073    threat          0      WHEAT
## 130  9743   6    13 131.1672  12.1920    threat          1       RASH
## 131  9744   6    14 143.3945   9.3837    threat          0       BABY
## 132  9768   6    38 389.1359  13.9377    threat          1      CAMEL
## 133  9769   6    39 403.1104   9.5289    threat          0      DAISY
## 134  9792   1    20 206.5058  11.1158    threat          1       DOLL
## 135  9793   1    21 217.7754   9.8078    threat          0        NET
## 136  9887   3    31 316.4073  12.6500    threat          1     PYTHON
## 137  9888   3    32 329.0896   9.0559    threat          0    PUMPKIN
## 138  9964   5    24 250.0028  11.9268    threat          1   ELEPHANT
## 139  9965   5    25 261.9648  10.1008    threat          0     RUDDER
## 140  9972   5    32 331.3766  11.7487    threat          1       FIRE
## 141  9973   5    33 343.1625   9.4118    threat          0      TULIP
## 142 10064   1    40 409.8509  11.1258    threat          1       FORK
## 143 10065   1    41 421.1248   9.2718    threat          0     PUDDLE
## 144 10120   3    12 125.2129  11.3880    threat          1   PASSPORT
## 145 10121   3    13 136.6359  11.1801    threat          0        FOX
## 146 10225   5    33 337.9285  11.9068    threat          1      APPLE
## 147 10226   5    34 349.8706  11.6155    threat          0   NECKLACE
## 148 10232   5    40 411.8589  11.8892    threat          1  CHOCOLATE
## 149 10233   5    41 423.7828   9.3700    threat          0       VINE
## 150 10334   2    16 163.6714  11.8030    threat          1   UMBRELLA
## 151 10335   2    17 175.5047  10.6519    threat          0    STOMACH
## 152 10412   4    10 103.6759  12.2727    threat          1     WALNUT
## 153 10413   4    11 115.9812   9.4173    threat          0       DOVE
## 154 10510   6    24 243.0234  12.1000    threat          1  CHOCOLATE
## 155 10511   6    25 255.1586  10.6464    threat          0    MUSTARD
## 156 10525   6    39 401.7446  11.9819    threat          1 TYPEWRITER
## 157 10526   6    40 413.7626   9.7478    threat          0       BONE
## 158 10608   2    38 386.7055  11.1138    threat          1       PLUG
## 159 10609   2    39 397.8499   9.6884    threat          0     VIOLIN
## 160 10659   4     5  55.3607  12.7068    threat          1     SHRIMP
## 161 10660   4     6  68.2091  10.0868    threat          0      SALAD
## 162 10743   6     5  55.3874  11.3702    threat          1    BLANKET
## 163 10744   6     6  66.7930   9.4131    threat          0      BRAIN
## 164 10762   6    24 247.0549  12.5635    threat          1    EMPEROR
## 165 10763   6    25 259.6565   9.5264    threat          0    RACQUET
## 166 11035   1     3  32.9018  11.9231    threat          1      ARMOR
## 167 11036   1     4  44.9635  10.0881    threat          0      GLOBE
## 168 11145   3    29 298.7042  11.6854    threat          1   SCORPION
## 169 11146   3    30 310.4258  11.6751    threat          0  ACCORDIAN
## 170 11217   5    17 175.5205  11.0963    threat          1       LAMP
## 171 11218   5    18 186.6540   9.2675    threat          0    OATMEAL
## 172 11220   5    20 206.0835  13.6732    threat          1     WALRUS
## 173 11221   5    21 219.7938  10.5466    threat          0       FROG
## 174 11287   1     3  30.6409  11.9242    threat          1     BANANA
## 175 11288   1     4  42.5929  11.6821    threat          0      SYRUP
## 176 11395   3    27 280.7332  14.3224    threat          1      SHARK
## 177 11396   3    28 295.2130   9.2906    threat          0       SOUP
## 178 11465   5    13 136.9597  11.7581    threat          1     RUDDER
## 179 11466   5    14 148.7535   9.7489    threat          0  ASPARAGUS
## 180 11490   5    38 392.5558  12.7040    threat          1    SUNBURN
## 181 11491   5    39 405.2980   9.1074    threat          0  LIGHTNING
## 182 11575   1    39 400.3330  12.9952    threat          1      KNIFE
## 183 11576   1    40 413.4640   9.8156    threat          0      OPIUM
## 184 11657   3    37 379.6906  12.6483    threat          1      QUAIL
## 185 11658   3    38 392.3713   9.6865    threat          0        PAN
## 186 11714   5    10 104.7707  11.1194    threat          1      EAGLE
## 187 11715   5    11 115.9277  11.6733    threat          0      SHARK
## 188 11721   5    17 180.2945  12.5609    threat          1    LANTERN
## 189 11722   5    18 192.8931  11.6123    threat          0     SANDAL
##              associate        resp         acc     accSpec   respRT subid
## 1               castle     outdoor           H       HO_Hi   3.4784 ap150
## 2                 foil      indoor          FA      FAI_Lo   1.5662 ap150
## 3        bowling_alley      indoor           H       HI_Hi   1.9713 ap150
## 4             heliport     outdoor           H       HO_Hi   2.0455 ap150
## 5            bookstore      indoor           H       HI_Lo   1.2885 ap150
## 6                 barn     outdoor           H       HO_Lo   1.5677 ap150
## 7             catacomb      indoor           H       HI_Hi   1.9171 ap150
## 8        butchers_shop      indoor           H       HI_Lo   2.1234 ap150
## 9                 foil no response no response no response 999.0000 ap151
## 10                foil no response no response no response 999.0000 ap151
## 11        control_room     outdoor          SM      SMI_Lo   2.6113 ap151
## 12             cockpit     outdoor          SM      SMI_Lo   1.8112 ap151
## 13                 inn      indoor          SM      SMO_Lo   0.0420 ap151
## 14        landing_deck      indoor          SM      SMO_Lo   1.4202 ap151
## 15               bayou        foil           M          MI   2.1244 ap151
## 16                foil     outdoor          FA      FAO_Lo   2.3634 ap151
## 17       hospital_room     outdoor          SM      SMI_Lo   2.2153 ap152
## 18                foil        foil          CR          CR   1.5186 ap152
## 19        bus_interior     outdoor          SM      SMI_Lo   1.7358 ap152
## 20           boat_deck     outdoor           H       HO_Lo   1.4701 ap152
## 21                foil no response no response no response 999.0000 ap152
## 22        chicken_coop     outdoor          SM      SMI_Lo   1.7785 ap152
## 23      amusement_park     outdoor           H       HO_Lo   4.0942 ap152
## 24               butte     outdoor           H       HO_Hi   1.4965 ap152
## 25                foil no response no response no response 999.0000 ap153
## 26             brewery      indoor           H       HI_Lo   3.4916 ap153
## 27      baseball_field      indoor          SM      SMO_Lo   1.9538 ap153
## 28            heliport     outdoor           H       HO_Lo   2.5545 ap153
## 29          rice_paddy     outdoor           H       HO_Lo   1.7886 ap153
## 30                foil        foil          CR          CR   2.7072 ap153
## 31      cottage_garden no response no response no response 999.0000 ap153
## 32          excavation     outdoor           H       HO_Lo   2.5612 ap153
## 33           carrousel     outdoor           H       HO_Lo   2.5473 ap154
## 34              harbor      indoor          SM      SMO_Lo   2.4948 ap154
## 35         picnic_area     outdoor           H       HO_Lo   2.2851 ap154
## 36                foil        foil          CR          CR   2.3313 ap154
## 37    field_cultivated no response no response no response 999.0000 ap154
## 38                foil      indoor          FA      FAI_Lo   2.7874 ap154
## 39                foil      indoor          FA      FAI_Lo   2.0466 ap154
## 40                foil        foil          CR          CR   1.0724 ap154
## 41        banquet_hall      indoor           H       HI_Hi   0.0624 ap155
## 42             cubicle     outdoor          SM      SMI_Hi   3.0532 ap155
## 43                moat      indoor          SM      SMO_Hi   0.0764 ap155
## 44             nursery     outdoor          SM      SMI_Hi   2.1297 ap155
## 45    ice_skating_rink no response no response no response 999.0000 ap156
## 46          art_studio      indoor           H       HI_Lo   2.0028 ap156
## 47           drugstore        foil           M          MI   1.7543 ap156
## 48                foil      indoor          FA      FAI_Lo   2.3347 ap156
## 49                foil no response no response no response 999.0000 ap156
## 50             nursery      indoor           H       HI_Hi   2.1255 ap156
## 51         boxing_ring      indoor           H       HI_Lo   1.4665 ap156
## 52               butte     outdoor           H       HO_Lo   1.5602 ap156
## 53           boardwalk      indoor          SM      SMO_Hi   2.7003 ap157
## 54  biology_laboratory     outdoor          SM      SMI_Lo   2.2663 ap157
## 55                foil      indoor          FA      FAI_Lo   2.5947 ap157
## 56         throne_room     outdoor          SM      SMI_Lo   3.2820 ap157
## 57               sauna        foil           M          MI   2.3324 ap157
## 58                foil        foil          CR          CR   1.9194 ap157
## 59                foil        foil          CR          CR   2.4756 ap157
## 60        squash_court      indoor           H       HI_Lo   3.7308 ap157
## 61                foil no response no response no response 999.0000 ap159
## 62                foil        foil          CR          CR   1.7951 ap159
## 63                foil no response no response no response 999.0000 ap159
## 64        car_interior        foil           M          MI   2.8011 ap159
## 65                foil        foil          CR          CR   0.0110 ap159
## 66                foil        foil          CR          CR   2.2897 ap159
## 67          hotel_room      indoor           H       HI_Lo   0.5815 ap159
## 68                foil        foil          CR          CR   1.5919 ap159
## 69                foil no response no response no response 999.0000 ap160
## 70                foil        foil          CR          CR   0.8235 ap160
## 71                foil        foil          CR          CR   1.6742 ap160
## 72               beach      indoor no response no response 999.0000 ap160
## 73  restaurant_kitchen no response no response no response 999.0000 ap160
## 74           game_room      indoor           H       HI_Hi   1.3730 ap160
## 75            aqueduct no response no response no response 999.0000 ap160
## 76               ocean     outdoor           H       HO_Hi   0.1927 ap160
## 77              bazaar        foil           M          MI   1.4969 ap160
## 78                foil no response no response no response 999.0000 ap161
## 79             archive        foil           M          MI   1.1672 ap161
## 80          hotel_room     outdoor          SM      SMI_Lo   2.0545 ap161
## 81        auto_factory     outdoor          SM      SMI_Lo   2.8225 ap161
## 82              harbor no response no response no response 999.0000 ap161
## 83              palace      indoor          SM      SMO_Lo   2.6534 ap161
## 84                foil      indoor          FA      FAI_Lo   0.0530 ap161
## 85                foil      indoor          FA      FAI_Hi   2.4873 ap161
## 86   forest_needleleaf      indoor          SM      SMO_Lo   3.4906 ap162
## 87                foil      indoor          FA      FAI_Hi   2.0639 ap162
## 88          greenhouse      indoor          SM      SMO_Lo   0.0078 ap162
## 89            cloister      indoor           H       HI_Hi   3.7735 ap162
## 90                foil        foil          CR          CR   1.8254 ap162
## 91              parlor      indoor           H       HI_Hi   2.8492 ap162
## 92                foil        foil          CR          CR   2.8869 ap162
## 93                 bar     outdoor          SM      SMI_Hi   1.9891 ap162
## 94               diner no response no response no response 999.0000 ap163
## 95      mountain_snowy     outdoor           H       HO_Hi   1.3257 ap163
## 96      parking_garage     outdoor          SM      SMI_Hi   3.6060 ap163
## 97                foil        foil          CR          CR   1.5522 ap163
## 98                foil        foil          CR          CR   2.7758 ap163
## 99              galley      indoor           H       HI_Hi   2.6550 ap163
## 100               foil no response no response no response 999.0000 ap163
## 101           elevator     outdoor          SM      SMI_Hi   3.8893 ap163
## 102           outhouse no response no response no response 999.0000 ap165
## 103               foil     outdoor          FA      FAO_Hi   2.2418 ap165
## 104            library      indoor           H       HI_Hi   3.0487 ap165
## 105         playground     outdoor           H       HO_Lo   2.5955 ap165
## 106         art_studio no response no response no response 999.0000 ap165
## 107             casino      indoor           H       HI_Hi   1.6615 ap165
## 108               foil     outdoor          FA      FAO_Hi   1.5531 ap165
## 109               foil        foil          CR          CR   1.8396 ap165
## 110               foil no response no response no response 999.0000 ap166
## 111       jewelry_shop      indoor           H       HI_Hi   1.3814 ap166
## 112               apse      indoor           H       HI_Lo   1.8952 ap166
## 113           cloister     outdoor          SM      SMI_Hi   3.3552 ap166
## 114               foil        foil          CR          CR   1.4887 ap166
## 115               foil        foil          CR          CR   1.6873 ap166
## 116           aquarium no response no response no response 999.0000 ap166
## 117            toyshop     outdoor          SM      SMI_Hi   1.7564 ap166
## 118  construction_site no response no response no response 999.0000 ap167
## 119               foil     outdoor          FA      FAO_Hi   2.1556 ap167
## 120            hot_tub     outdoor           H       HO_Lo   0.1760 ap167
## 121               foil     outdoor          FA      FAO_Hi   2.3297 ap167
## 122               foil        foil          CR          CR   0.1413 ap167
## 123             desert        foil           M          MI   2.2095 ap167
## 124               foil        foil          CR          CR   1.1858 ap167
## 125         lighthouse        foil           M          MI   1.0927 ap167
## 126        throne_room no response no response no response 999.0000 ap169
## 127          courtroom        foil           M          MI   1.9232 ap169
## 128      watering_hole     outdoor           H       HO_Hi   2.3657 ap169
## 129        childs_room     outdoor          SM      SMI_Hi   2.8110 ap169
## 130           aquarium no response no response no response 999.0000 ap169
## 131      putting_green        foil           M          MI   2.8250 ap169
## 132               foil no response no response no response 999.0000 ap169
## 133             harbor        foil           M          MI   1.8486 ap169
## 134            toyshop        foil           M          MI   1.2386 ap170
## 135          crosswalk     outdoor           H       HO_Hi   2.4052 ap170
## 136        phone_booth     outdoor           H       HO_Hi   0.8689 ap170
## 137             kennel     outdoor          SM      SMI_Lo   2.4475 ap170
## 138       auto_factory     outdoor          SM      SMI_Hi   0.7318 ap170
## 139       chicken_coop     outdoor          SM      SMI_Lo   3.6921 ap170
## 140               foil        foil          CR          CR   2.5005 ap170
## 141               foil        foil          CR          CR   2.5760 ap170
## 142               foil     outdoor          FA      FAO_Lo   1.7813 ap172
## 143               foil      indoor          FA      FAI_Lo   1.2331 ap172
## 144              cliff     outdoor           H       HO_Hi   2.6850 ap172
## 145               foil     outdoor          FA      FAO_Lo   2.2064 ap172
## 146      computer_room no response no response no response 999.0000 ap172
## 147            balcony      indoor          SM      SMO_Lo   2.0357 ap172
## 148             corral no response no response no response 999.0000 ap172
## 149           ball_pit      indoor           H       HI_Lo   1.5934 ap172
## 150         art_studio      indoor           H       HI_Lo   0.0960 ap173
## 151               foil        foil          CR          CR   1.6203 ap173
## 152          labyrinth        foil           M          MI   0.0595 ap173
## 153               foil     outdoor          FA      FAO_Lo   1.6019 ap173
## 154               foil        foil          CR          CR   2.2311 ap173
## 155           ice_floe        foil           M          MI   0.5755 ap173
## 156              stage no response no response no response 999.0000 ap173
## 157               foil        foil          CR          CR   0.6016 ap173
## 158               foil no response no response no response 999.0000 ap171
## 159          bookstore      indoor           H       HI_Hi   2.3229 ap171
## 160               ruin     outdoor           H       HO_Lo   1.8824 ap171
## 161       jewelry_shop     outdoor          SM      SMI_Lo   1.8924 ap171
## 162              patio no response no response no response 999.0000 ap171
## 163            cockpit     outdoor          SM      SMI_Lo   1.8604 ap171
## 164               foil        foil          CR          CR   1.1141 ap171
## 165       lock_chamber        foil           M          MI   1.4302 ap171
## 166       beauty_salon     outdoor          SM      SMI_Lo   1.1529 ap168
## 167      swimming_pool     outdoor          SM      SMI_Hi   1.4554 ap168
## 168          rock_arch     outdoor           H       HO_Hi   1.9075 ap168
## 169      general_store      indoor          SM      SMO_Lo   2.7764 ap168
## 170       music_studio     outdoor          SM      SMI_Hi   2.7333 ap168
## 171          lido_deck        foil           M          MI   1.2860 ap168
## 172               foil        foil          CR          CR   0.4739 ap168
## 173           outhouse     outdoor           H       HO_Lo   2.0904 ap168
## 174       jewelry_shop no response no response no response 999.0000 ap164
## 175             kennel      indoor           H       HI_Lo   2.5060 ap164
## 176    subway_interior      indoor           H       HI_Hi   2.6877 ap164
## 177      bowling_alley      indoor           H       HI_Lo   2.1773 ap164
## 178   amusement_arcade no response no response no response 999.0000 ap164
## 179               foil      indoor          FA      FAI_Lo   3.7373 ap164
## 180               foil     outdoor          FA      FAO_Lo   2.1194 ap164
## 181      watering_hole      indoor          SM      SMO_Lo   1.4898 ap164
## 182               foil      indoor          FA      FAI_Lo   2.4353 ap174
## 183               foil        foil          CR          CR   1.3682 ap174
## 184         art_studio     outdoor          SM      SMI_Hi   0.2030 ap174
## 185      formal_garden      indoor          SM      SMO_Lo   3.2013 ap174
## 186           fishpond     outdoor           H       HO_Lo   2.5289 ap174
## 187              diner      indoor           H       HI_Hi   1.5974 ap174
## 188    subway_interior      indoor           H       HI_Lo   0.1130 ap174
## 189               foil     outdoor          FA      FAO_Hi   2.5575 ap174
##           group remove anxious happy safe stressed life_stress sleep
## 1   stress-fmri     NA       4     2    4        5           3   7.5
## 2   stress-fmri     NA       4     2    4        5           3   7.5
## 3   stress-fmri     NA       4     2    4        5           3   7.5
## 4   stress-fmri     NA       4     2    4        5           3   7.5
## 5   stress-fmri     NA       4     2    4        5           3   7.5
## 6   stress-fmri     NA       4     2    4        5           3   7.5
## 7   stress-fmri     NA       4     2    4        5           3   7.5
## 8   stress-fmri     NA       4     2    4        5           3   7.5
## 9   stress-fmri     NA       6     1    3        5           4   9.0
## 10  stress-fmri     NA       6     1    3        5           4   9.0
## 11  stress-fmri     NA       6     1    3        5           4   9.0
## 12  stress-fmri     NA       6     1    3        5           4   9.0
## 13  stress-fmri     NA       6     1    3        5           4   9.0
## 14  stress-fmri     NA       6     1    3        5           4   9.0
## 15  stress-fmri     NA       6     1    3        5           4   9.0
## 16  stress-fmri     NA       6     1    3        5           4   9.0
## 17  stress-fmri     NA       3     4    5        6           3   9.0
## 18  stress-fmri     NA       3     4    5        6           3   9.0
## 19  stress-fmri     NA       3     4    5        6           3   9.0
## 20  stress-fmri     NA       3     4    5        6           3   9.0
## 21  stress-fmri     NA       3     4    5        6           3   9.0
## 22  stress-fmri     NA       3     4    5        6           3   9.0
## 23  stress-fmri     NA       3     4    5        6           3   9.0
## 24  stress-fmri     NA       3     4    5        6           3   9.0
## 25  stress-fmri     NA       2     5    5        2           4   7.0
## 26  stress-fmri     NA       2     5    5        2           4   7.0
## 27  stress-fmri     NA       2     5    5        2           4   7.0
## 28  stress-fmri     NA       2     5    5        2           4   7.0
## 29  stress-fmri     NA       2     5    5        2           4   7.0
## 30  stress-fmri     NA       2     5    5        2           4   7.0
## 31  stress-fmri     NA       2     5    5        2           4   7.0
## 32  stress-fmri     NA       2     5    5        2           4   7.0
## 33  stress-fmri     NA       5     4    4        5           4   8.0
## 34  stress-fmri     NA       5     4    4        5           4   8.0
## 35  stress-fmri     NA       5     4    4        5           4   8.0
## 36  stress-fmri     NA       5     4    4        5           4   8.0
## 37  stress-fmri     NA       5     4    4        5           4   8.0
## 38  stress-fmri     NA       5     4    4        5           4   8.0
## 39  stress-fmri     NA       5     4    4        5           4   8.0
## 40  stress-fmri     NA       5     4    4        5           4   8.0
## 41  stress-fmri     NA       3     5    6        2           2   8.0
## 42  stress-fmri     NA       3     5    6        2           2   8.0
## 43  stress-fmri     NA       3     5    6        2           2   8.0
## 44  stress-fmri     NA       3     5    6        2           2   8.0
## 45  stress-fmri     NA       3     2    7        3           2   9.0
## 46  stress-fmri     NA       3     2    7        3           2   9.0
## 47  stress-fmri     NA       3     2    7        3           2   9.0
## 48  stress-fmri     NA       3     2    7        3           2   9.0
## 49  stress-fmri     NA       3     2    7        3           2   9.0
## 50  stress-fmri     NA       3     2    7        3           2   9.0
## 51  stress-fmri     NA       3     2    7        3           2   9.0
## 52  stress-fmri     NA       3     2    7        3           2   9.0
## 53  stress-fmri     NA       3     2    5        3           3   8.0
## 54  stress-fmri     NA       3     2    5        3           3   8.0
## 55  stress-fmri     NA       3     2    5        3           3   8.0
## 56  stress-fmri     NA       3     2    5        3           3   8.0
## 57  stress-fmri     NA       3     2    5        3           3   8.0
## 58  stress-fmri     NA       3     2    5        3           3   8.0
## 59  stress-fmri     NA       3     2    5        3           3   8.0
## 60  stress-fmri     NA       3     2    5        3           3   8.0
## 61  stress-fmri     NA       5     3    5        4           6  12.0
## 62  stress-fmri     NA       5     3    5        4           6  12.0
## 63  stress-fmri     NA       5     3    5        4           6  12.0
## 64  stress-fmri     NA       5     3    5        4           6  12.0
## 65  stress-fmri     NA       5     3    5        4           6  12.0
## 66  stress-fmri     NA       5     3    5        4           6  12.0
## 67  stress-fmri     NA       5     3    5        4           6  12.0
## 68  stress-fmri     NA       5     3    5        4           6  12.0
## 69  stress-fmri     NA       4     3    6        5           3   4.5
## 70  stress-fmri     NA       4     3    6        5           3   4.5
## 71  stress-fmri     NA       4     3    6        5           3   4.5
## 72  stress-fmri     NA       4     3    6        5           3   4.5
## 73  stress-fmri     NA       4     3    6        5           3   4.5
## 74  stress-fmri     NA       4     3    6        5           3   4.5
## 75  stress-fmri     NA       4     3    6        5           3   4.5
## 76  stress-fmri     NA       4     3    6        5           3   4.5
## 77  stress-fmri     NA       4     3    6        5           3   4.5
## 78  stress-fmri     NA       3     3    7        6           5   6.0
## 79  stress-fmri     NA       3     3    7        6           5   6.0
## 80  stress-fmri     NA       3     3    7        6           5   6.0
## 81  stress-fmri     NA       3     3    7        6           5   6.0
## 82  stress-fmri     NA       3     3    7        6           5   6.0
## 83  stress-fmri     NA       3     3    7        6           5   6.0
## 84  stress-fmri     NA       3     3    7        6           5   6.0
## 85  stress-fmri     NA       3     3    7        6           5   6.0
## 86  stress-fmri     NA       3     2    4        5           3   7.0
## 87  stress-fmri     NA       3     2    4        5           3   7.0
## 88  stress-fmri     NA       3     2    4        5           3   7.0
## 89  stress-fmri     NA       3     2    4        5           3   7.0
## 90  stress-fmri     NA       3     2    4        5           3   7.0
## 91  stress-fmri     NA       3     2    4        5           3   7.0
## 92  stress-fmri     NA       3     2    4        5           3   7.0
## 93  stress-fmri     NA       3     2    4        5           3   7.0
## 94  stress-fmri     NA       3     2    4        3           4   8.0
## 95  stress-fmri     NA       3     2    4        3           4   8.0
## 96  stress-fmri     NA       3     2    4        3           4   8.0
## 97  stress-fmri     NA       3     2    4        3           4   8.0
## 98  stress-fmri     NA       3     2    4        3           4   8.0
## 99  stress-fmri     NA       3     2    4        3           4   8.0
## 100 stress-fmri     NA       3     2    4        3           4   8.0
## 101 stress-fmri     NA       3     2    4        3           4   8.0
## 102 stress-fmri     NA       5     2    5        5           2   7.5
## 103 stress-fmri     NA       5     2    5        5           2   7.5
## 104 stress-fmri     NA       5     2    5        5           2   7.5
## 105 stress-fmri     NA       5     2    5        5           2   7.5
## 106 stress-fmri     NA       5     2    5        5           2   7.5
## 107 stress-fmri     NA       5     2    5        5           2   7.5
## 108 stress-fmri     NA       5     2    5        5           2   7.5
## 109 stress-fmri     NA       5     2    5        5           2   7.5
## 110 stress-fmri     NA       5     2    5        4           4   6.0
## 111 stress-fmri     NA       5     2    5        4           4   6.0
## 112 stress-fmri     NA       5     2    5        4           4   6.0
## 113 stress-fmri     NA       5     2    5        4           4   6.0
## 114 stress-fmri     NA       5     2    5        4           4   6.0
## 115 stress-fmri     NA       5     2    5        4           4   6.0
## 116 stress-fmri     NA       5     2    5        4           4   6.0
## 117 stress-fmri     NA       5     2    5        4           4   6.0
## 118 stress-fmri     NA       6     2    3        6           3   9.0
## 119 stress-fmri     NA       6     2    3        6           3   9.0
## 120 stress-fmri     NA       6     2    3        6           3   9.0
## 121 stress-fmri     NA       6     2    3        6           3   9.0
## 122 stress-fmri     NA       6     2    3        6           3   9.0
## 123 stress-fmri     NA       6     2    3        6           3   9.0
## 124 stress-fmri     NA       6     2    3        6           3   9.0
## 125 stress-fmri     NA       6     2    3        6           3   9.0
## 126 stress-fmri     NA       5     2    5        4           4   7.5
## 127 stress-fmri     NA       5     2    5        4           4   7.5
## 128 stress-fmri     NA       5     2    5        4           4   7.5
## 129 stress-fmri     NA       5     2    5        4           4   7.5
## 130 stress-fmri     NA       5     2    5        4           4   7.5
## 131 stress-fmri     NA       5     2    5        4           4   7.5
## 132 stress-fmri     NA       5     2    5        4           4   7.5
## 133 stress-fmri     NA       5     2    5        4           4   7.5
## 134 stress-fmri     NA       2     1    7        3           5   6.0
## 135 stress-fmri     NA       2     1    7        3           5   6.0
## 136 stress-fmri     NA       2     1    7        3           5   6.0
## 137 stress-fmri     NA       2     1    7        3           5   6.0
## 138 stress-fmri     NA       2     1    7        3           5   6.0
## 139 stress-fmri     NA       2     1    7        3           5   6.0
## 140 stress-fmri     NA       2     1    7        3           5   6.0
## 141 stress-fmri     NA       2     1    7        3           5   6.0
## 142 stress-fmri     NA       4     2    4        5           6   6.0
## 143 stress-fmri     NA       4     2    4        5           6   6.0
## 144 stress-fmri     NA       4     2    4        5           6   6.0
## 145 stress-fmri     NA       4     2    4        5           6   6.0
## 146 stress-fmri     NA       4     2    4        5           6   6.0
## 147 stress-fmri     NA       4     2    4        5           6   6.0
## 148 stress-fmri     NA       4     2    4        5           6   6.0
## 149 stress-fmri     NA       4     2    4        5           6   6.0
## 150 stress-fmri     NA       6     2    3        5           4   9.5
## 151 stress-fmri     NA       6     2    3        5           4   9.5
## 152 stress-fmri     NA       6     2    3        5           4   9.5
## 153 stress-fmri     NA       6     2    3        5           4   9.5
## 154 stress-fmri     NA       6     2    3        5           4   9.5
## 155 stress-fmri     NA       6     2    3        5           4   9.5
## 156 stress-fmri     NA       6     2    3        5           4   9.5
## 157 stress-fmri     NA       6     2    3        5           4   9.5
## 158 stress-fmri     NA       3     3    3        4           3   7.5
## 159 stress-fmri     NA       3     3    3        4           3   7.5
## 160 stress-fmri     NA       3     3    3        4           3   7.5
## 161 stress-fmri     NA       3     3    3        4           3   7.5
## 162 stress-fmri     NA       3     3    3        4           3   7.5
## 163 stress-fmri     NA       3     3    3        4           3   7.5
## 164 stress-fmri     NA       3     3    3        4           3   7.5
## 165 stress-fmri     NA       3     3    3        4           3   7.5
## 166 stress-fmri     NA       7     2    5        7           6   8.0
## 167 stress-fmri     NA       7     2    5        7           6   8.0
## 168 stress-fmri     NA       7     2    5        7           6   8.0
## 169 stress-fmri     NA       7     2    5        7           6   8.0
## 170 stress-fmri     NA       7     2    5        7           6   8.0
## 171 stress-fmri     NA       7     2    5        7           6   8.0
## 172 stress-fmri     NA       7     2    5        7           6   8.0
## 173 stress-fmri     NA       7     2    5        7           6   8.0
## 174 stress-fmri     NA       6     2    3        6           5   9.0
## 175 stress-fmri     NA       6     2    3        6           5   9.0
## 176 stress-fmri     NA       6     2    3        6           5   9.0
## 177 stress-fmri     NA       6     2    3        6           5   9.0
## 178 stress-fmri     NA       6     2    3        6           5   9.0
## 179 stress-fmri     NA       6     2    3        6           5   9.0
## 180 stress-fmri     NA       6     2    3        6           5   9.0
## 181 stress-fmri     NA       6     2    3        6           5   9.0
## 182 stress-fmri     NA       2     6    7        2           3   9.0
## 183 stress-fmri     NA       2     6    7        2           3   9.0
## 184 stress-fmri     NA       2     6    7        2           3   9.0
## 185 stress-fmri     NA       2     6    7        2           3   9.0
## 186 stress-fmri     NA       2     6    7        2           3   9.0
## 187 stress-fmri     NA       2     6    7        2           3   9.0
## 188 stress-fmri     NA       2     6    7        2           3   9.0
## 189 stress-fmri     NA       2     6    7        2           3   9.0
##     cond_orig    cond reps shock_and_post conf onset_adj mem_conditions
## 1        TO_2 outdoor    2              1   Hi  376.8635       nuisance
## 2         F_0    foil    0              1   Lo  390.5077       nuisance
## 3        TI_4  indoor    4              1   Hi  320.6727       nuisance
## 4        TO_2 outdoor    2              1   Hi  334.0418       nuisance
## 5        TI_2  indoor    2              1   Lo   40.4561       nuisance
## 6        TO_4 outdoor    4              1   Lo   53.4843       nuisance
## 7        TI_4  indoor    4              1   Hi  268.4064       nuisance
## 8        TI_4  indoor    4              1   Lo  282.0577       nuisance
## 9         F_0    foil    0              1    N  150.8869       nuisance
## 10        F_0    foil    0              1    N  162.3062       nuisance
## 11       TI_4  indoor    4              1   Lo  176.7935       nuisance
## 12       TI_4  indoor    4              1   Lo  188.9294       nuisance
## 13       TO_2 outdoor    2              1   Lo  207.7744       nuisance
## 14       TO_4 outdoor    4              1   Lo  220.3590       nuisance
## 15       TO_2 outdoor    2              1    N  282.0528       nuisance
## 16        F_0    foil    0              1   Lo  293.2337       nuisance
## 17       TI_2  indoor    2              1   Lo   57.5282       nuisance
## 18        F_0    foil    0              1    N   72.2717       nuisance
## 19       TI_2  indoor    2              1   Lo  325.3948       nuisance
## 20       TO_2 outdoor    2              1   Lo  337.3487       nuisance
## 21        F_0    foil    0              1    N   69.0813       nuisance
## 22       TI_4  indoor    4              1   Lo   80.2900       nuisance
## 23       TO_4 outdoor    4              1   Lo  216.0153       nuisance
## 24       TO_2 outdoor    2              1   Hi  227.7295       nuisance
## 25        F_0    foil    0              1    N  346.2914       nuisance
## 26       TI_2  indoor    2              1   Lo  357.5712       nuisance
## 27       TO_4 outdoor    4              1   Lo  133.5132       nuisance
## 28       TO_2 outdoor    2              1   Lo  145.2813       nuisance
## 29       TO_2 outdoor    2              1   Lo    0.0050       nuisance
## 30        F_0    foil    0              1    N   12.5388       nuisance
## 31       TO_2 outdoor    2              1    N   81.6401       nuisance
## 32       TO_4 outdoor    4              1   Lo   93.4761       nuisance
## 33       TO_4 outdoor    4              1   Lo  182.7396       nuisance
## 34       TO_2 outdoor    2              1   Lo  194.7664       nuisance
## 35       TO_2 outdoor    2              1   Lo   18.7302       nuisance
## 36        F_0    foil    0              1    N   30.1530       nuisance
## 37       TO_4 outdoor    4              1    N   22.1849       nuisance
## 38        F_0    foil    0              1   Lo   34.1465       nuisance
## 39        F_0    foil    0              1   Lo  362.1904       nuisance
## 40        F_0    foil    0              1    N  374.8735       nuisance
## 41       TI_4  indoor    4              1   Hi  377.7051       nuisance
## 42       TI_4  indoor    4              1   Hi  390.2028       nuisance
## 43       TO_2 outdoor    2              1   Hi  303.3568       nuisance
## 44       TI_4  indoor    4              1   Hi  315.2968       nuisance
## 45       TI_2  indoor    2              1    N  327.4238       nuisance
## 46       TI_4  indoor    4              1   Lo  338.5082       nuisance
## 47       TI_2  indoor    2              1    N  304.0909       nuisance
## 48        F_0    foil    0              1   Lo  317.4975       nuisance
## 49        F_0    foil    0              1    N  127.8456       nuisance
## 50       TI_4  indoor    4              1   Hi  141.2127       nuisance
## 51       TI_4  indoor    4              1   Lo  150.3878       nuisance
## 52       TO_4 outdoor    4              1   Lo  163.6882       nuisance
## 53       TO_4 outdoor    4              1   Hi  276.3530       nuisance
## 54       TI_2  indoor    2              1   Lo  289.2897       nuisance
## 55        F_0    foil    0              1   Lo  242.2745       nuisance
## 56       TI_2  indoor    2              1   Lo  256.6304       nuisance
## 57       TI_2  indoor    2              1    N   81.2720       nuisance
## 58        F_0    foil    0              1    N   94.0143       nuisance
## 59        F_0    foil    0              1    N  376.5212       nuisance
## 60       TI_4  indoor    4              1   Lo  388.6577       nuisance
## 61        F_0    foil    0              1    N  251.0002       nuisance
## 62        F_0    foil    0              1    N  263.2265       nuisance
## 63        F_0    foil    0              1    N  349.1516       nuisance
## 64       TI_2  indoor    2              1    N  362.8610       nuisance
## 65        F_0    foil    0              1    N  196.5525       nuisance
## 66        F_0    foil    0              1    N  208.9555       nuisance
## 67       TI_2  indoor    2              1   Lo  383.3022       nuisance
## 68        F_0    foil    0              1    N  394.7067       nuisance
## 69        F_0    foil    0              1    N  185.5353       nuisance
## 70        F_0    foil    0              1    N  198.8293       nuisance
## 71        F_0    foil    0              1    N  401.6314       nuisance
## 72       TO_2 outdoor    2              1    N  412.8264       nuisance
## 73       TI_2  indoor    2              1    N  156.0995       nuisance
## 74       TI_4  indoor    4              1   Hi  167.7602       nuisance
## 75       TO_2 outdoor    2              1    N  117.1745       nuisance
## 76       TO_4 outdoor    4              2   Hi  129.3117       nuisance
## 77       TI_2  indoor    2              1    N  140.8769       nuisance
## 78        F_0    foil    0              1    N  183.2545       nuisance
## 79       TI_2  indoor    2              1    N  197.6069       nuisance
## 80       TI_4  indoor    4              1   Lo  263.6425       nuisance
## 81       TI_2  indoor    2              1   Lo  275.4599       nuisance
## 82       TO_4 outdoor    4              1    N   71.6481       nuisance
## 83       TO_4 outdoor    4              1   Lo   83.0966       nuisance
## 84        F_0    foil    0              1   Lo  131.4211       nuisance
## 85        F_0    foil    0              1   Hi  143.3631       nuisance
## 86       TO_2 outdoor    2              1   Lo  317.2043       nuisance
## 87        F_0    foil    0              1   Hi  328.7563       nuisance
## 88       TO_2 outdoor    2              1   Lo  304.7444       nuisance
## 89       TI_2  indoor    2              1   Hi  315.8903       nuisance
## 90        F_0    foil    0              1    N   30.1248       nuisance
## 91       TI_4  indoor    4              1   Hi   42.0802       nuisance
## 92        F_0    foil    0              1    N  306.8659       nuisance
## 93       TI_2  indoor    2              1   Hi  318.0435       nuisance
## 94       TI_4  indoor    4              1    N  164.4960       nuisance
## 95       TO_4 outdoor    4              1   Hi  177.8603       nuisance
## 96       TI_4  indoor    4              1   Hi  240.1435       nuisance
## 97        F_0    foil    0              1    N  252.9348       nuisance
## 98        F_0    foil    0              1    N   31.3746       nuisance
## 99       TI_4  indoor    4              1   Hi   43.9605       nuisance
## 100       F_0    foil    0              1    N  304.6024       nuisance
## 101      TI_2  indoor    2              1   Hi  316.8293       nuisance
## 102      TO_2 outdoor    2              1    N   31.1248       nuisance
## 103       F_0    foil    0              1   Hi   43.2492       nuisance
## 104      TI_2  indoor    2              1   Hi   48.3592       nuisance
## 105      TO_4 outdoor    4              1   Lo   60.6665       nuisance
## 106      TI_4  indoor    4              1    N  171.3171       nuisance
## 107      TI_2  indoor    2              1   Hi  184.5336       nuisance
## 108       F_0    foil    0              1   Hi  288.6094       nuisance
## 109       F_0    foil    0              1    N  300.4025       nuisance
## 110       F_0    foil    0              1    N  274.1872       nuisance
## 111      TI_4  indoor    4              1   Hi  285.9053       nuisance
## 112      TI_4  indoor    4              1   Lo   88.1384       nuisance
## 113      TI_4  indoor    4              1   Hi   99.6157       nuisance
## 114       F_0    foil    0              1    N   94.2110       nuisance
## 115       F_0    foil    0              1    N  106.9534       nuisance
## 116      TI_2  indoor    2              1    N  408.2549       nuisance
## 117      TI_4  indoor    4              1   Hi  422.6141       nuisance
## 118      TO_4 outdoor    4              1    N   80.6728       nuisance
## 119       F_0    foil    0              1   Hi   92.3876       nuisance
## 120      TO_2 outdoor    2              1   Lo   63.6126       nuisance
## 121       F_0    foil    0              1   Hi   76.0141       nuisance
## 122       F_0    foil    0              1    N  180.0202       nuisance
## 123      TO_4 outdoor    4              1    N  193.2341       nuisance
## 124       F_0    foil    0              1    N  291.3809       nuisance
## 125      TO_2 outdoor    2              1    N  303.5210       nuisance
## 126      TI_4  indoor    4              1    N   32.0804       nuisance
## 127      TI_2  indoor    2              1    N   44.7611       nuisance
## 128      TO_2 outdoor    2              1   Hi  113.3795       nuisance
## 129      TI_4  indoor    4              1   Hi  126.8557       nuisance
## 130      TI_2  indoor    2              1    N  119.1672       nuisance
## 131      TO_2 outdoor    2              1    N  131.3945       nuisance
## 132       F_0    foil    0              1    N  377.1359       nuisance
## 133      TO_4 outdoor    4              1    N  391.1104       nuisance
## 134      TI_2  indoor    2              1    N  194.5058       nuisance
## 135      TO_4 outdoor    4              1   Hi  205.7754       nuisance
## 136      TO_4 outdoor    4              1   Hi  304.4073       nuisance
## 137      TI_4  indoor    4              1   Lo  317.0896       nuisance
## 138      TI_2  indoor    2              1   Hi  238.0028       nuisance
## 139      TI_2  indoor    2              1   Lo  249.9648       nuisance
## 140       F_0    foil    0              1    N  319.3766       nuisance
## 141       F_0    foil    0              1    N  331.1625       nuisance
## 142       F_0    foil    0              1   Lo  397.8509       nuisance
## 143       F_0    foil    0              1   Lo  409.1248       nuisance
## 144      TO_4 outdoor    4              1   Hi  113.2129       nuisance
## 145       F_0    foil    0              1   Lo  124.6359       nuisance
## 146      TI_4  indoor    4              1    N  325.9285       nuisance
## 147      TO_4 outdoor    4              1   Lo  337.8706       nuisance
## 148      TO_4 outdoor    4              1    N  399.8589       nuisance
## 149      TI_2  indoor    2              1   Lo  411.7828       nuisance
## 150      TI_2  indoor    2              1   Lo  151.6714       nuisance
## 151       F_0    foil    0              1    N  163.5047       nuisance
## 152      TO_2 outdoor    2              1    N   91.6759       nuisance
## 153       F_0    foil    0              1   Lo  103.9812       nuisance
## 154       F_0    foil    0              1    N  231.0234       nuisance
## 155      TO_2 outdoor    2              1    N  243.1586       nuisance
## 156      TI_2  indoor    2              1    N  389.7446       nuisance
## 157       F_0    foil    0              1    N  401.7626       nuisance
## 158       F_0    foil    0              1    N  374.7055       nuisance
## 159      TI_4  indoor    4              1   Hi  385.8499       nuisance
## 160      TO_4 outdoor    4              1   Lo   43.3607       nuisance
## 161      TI_2  indoor    2              1   Lo   56.2091       nuisance
## 162      TO_2 outdoor    2              1    N   43.3874       nuisance
## 163      TI_2  indoor    2              1   Lo   54.7930       nuisance
## 164       F_0    foil    0              1    N  235.0549       nuisance
## 165      TO_4 outdoor    4              1    N  247.6565       nuisance
## 166      TI_2  indoor    2              1   Lo   20.9018       nuisance
## 167      TI_2  indoor    2              1   Hi   32.9635       nuisance
## 168      TO_2 outdoor    2              1   Hi  286.7042       nuisance
## 169      TO_2 outdoor    2              1   Lo  298.4258       nuisance
## 170      TI_2  indoor    2              1   Hi  163.5205       nuisance
## 171      TO_4 outdoor    4              1    N  174.6540       nuisance
## 172       F_0    foil    0              1    N  194.0835       nuisance
## 173      TO_4 outdoor    4              1   Lo  207.7938       nuisance
## 174      TI_2  indoor    2              1    N   18.6409       nuisance
## 175      TI_4  indoor    4              1   Lo   30.5929       nuisance
## 176      TI_4  indoor    4              1   Hi  268.7332       nuisance
## 177      TI_2  indoor    2              1   Lo  283.2130       nuisance
## 178      TI_4  indoor    4              1    N  124.9597       nuisance
## 179       F_0    foil    0              1   Lo  136.7535       nuisance
## 180       F_0    foil    0              1   Lo  380.5558       nuisance
## 181      TO_4 outdoor    4              1   Lo  393.2980       nuisance
## 182       F_0    foil    0              1   Lo  388.3330       nuisance
## 183       F_0    foil    0              1    N  401.4640       nuisance
## 184      TI_4  indoor    4              1   Hi  367.6906       nuisance
## 185      TO_2 outdoor    2              1   Lo  380.3713       nuisance
## 186      TO_2 outdoor    2              1   Lo   92.7707       nuisance
## 187      TI_4  indoor    4              1   Hi  103.9277       nuisance
## 188      TI_2  indoor    2              1   Lo  168.2945       nuisance
## 189       F_0    foil    0              1   Hi  180.8931       nuisance
##     obj_conditions onset_code        rt_z mem_conditions_byrep
## 1         nuisance   nuisance -1.02609880           nuisance-2
## 2         nuisance   nuisance -1.02982661           nuisance-0
## 3         nuisance   nuisance -1.02903687           nuisance-4
## 4         nuisance   nuisance -1.02889222           nuisance-2
## 5         nuisance   nuisance -1.03036798           nuisance-2
## 6         nuisance   nuisance -1.02982369           nuisance-4
## 7         nuisance   nuisance -1.02914254           nuisance-4
## 8         nuisance   nuisance -1.02874036           nuisance-4
## 9         nuisance   nuisance  1.16189396           nuisance-0
## 10        nuisance   nuisance  1.16189396           nuisance-0
## 11        nuisance   nuisance -0.77288225           nuisance-4
## 12        nuisance   nuisance -0.77443587           nuisance-4
## 13        nuisance   nuisance -0.77787129           nuisance-2
## 14        nuisance   nuisance -0.77519511           nuisance-4
## 15        nuisance   nuisance -0.77382771           nuisance-2
## 16        nuisance   nuisance -0.77336362           nuisance-0
## 17        nuisance   nuisance -0.35306673           nuisance-2
## 18        nuisance   nuisance -0.35504331           nuisance-0
## 19        nuisance   nuisance -0.35442710           nuisance-2
## 20        nuisance   nuisance -0.35518090           nuisance-2
## 21        nuisance   nuisance  2.47486619           nuisance-0
## 22        nuisance   nuisance -0.35430596           nuisance-4
## 23        nuisance   nuisance -0.34773619           nuisance-4
## 24        nuisance   nuisance -0.35510601           nuisance-2
## 25        nuisance   nuisance  1.16189456           nuisance-0
## 26        nuisance   nuisance -0.77268781           nuisance-2
## 27        nuisance   nuisance -0.77567624           nuisance-4
## 28        nuisance   nuisance -0.77450889           nuisance-2
## 29        nuisance   nuisance -0.77599727           nuisance-2
## 30        nuisance   nuisance -0.77421215           nuisance-0
## 31        nuisance   nuisance  1.16189456           nuisance-2
## 32        nuisance   nuisance -0.77449587           nuisance-4
## 33        nuisance   nuisance -0.96299790           nuisance-4
## 34        nuisance   nuisance -0.96309941           nuisance-2
## 35        nuisance   nuisance -0.96350486           nuisance-2
## 36        nuisance   nuisance -0.96341553           nuisance-0
## 37        nuisance   nuisance  0.96362385           nuisance-4
## 38        nuisance   nuisance -0.96253367           nuisance-0
## 39        nuisance   nuisance -0.96396600           nuisance-0
## 40        nuisance   nuisance -0.96584959           nuisance-0
## 41        nuisance   nuisance -0.45005369           nuisance-4
## 42        nuisance   nuisance -0.44335047           nuisance-4
## 43        nuisance   nuisance -0.45002231           nuisance-2
## 44        nuisance   nuisance -0.44542029           nuisance-4
## 45        nuisance   nuisance  0.88949910           nuisance-2
## 46        nuisance   nuisance -1.03750001           nuisance-4
## 47        nuisance   nuisance -1.03798031           nuisance-2
## 48        nuisance   nuisance -1.03685851           nuisance-0
## 49        nuisance   nuisance  0.88949910           nuisance-0
## 50        nuisance   nuisance -1.03726285           nuisance-4
## 51        nuisance   nuisance -1.03853657           nuisance-4
## 52        nuisance   nuisance -1.03835546           nuisance-4
## 53        nuisance   nuisance  0.06444887           nuisance-4
## 54        nuisance   nuisance -0.67920844           nuisance-2
## 55        nuisance   nuisance -0.11649632           nuisance-0
## 56        nuisance   nuisance  1.06118956           nuisance-2
## 57        nuisance   nuisance -0.56594635           nuisance-2
## 58        nuisance   nuisance -1.27362024           nuisance-0
## 59        nuisance   nuisance -0.32057370           nuisance-0
## 60        nuisance   nuisance  1.83020662           nuisance-4
## 61        nuisance   nuisance  1.16189367           nuisance-0
## 62        nuisance   nuisance -0.77404563           nuisance-0
## 63        nuisance   nuisance  1.16189367           nuisance-0
## 64        nuisance   nuisance -0.77209262           nuisance-2
## 65        nuisance   nuisance -0.77750922           nuisance-0
## 66        nuisance   nuisance -0.77308543           nuisance-0
## 67        nuisance   nuisance -0.77640167           nuisance-2
## 68        nuisance   nuisance -0.77444012           nuisance-0
## 69        nuisance   nuisance  0.31333973           nuisance-0
## 70        nuisance   nuisance -3.13439400           nuisance-0
## 71        nuisance   nuisance -3.13145565           nuisance-0
## 72        nuisance   nuisance  0.31333973           nuisance-2
## 73        nuisance   nuisance  0.31333973           nuisance-2
## 74        nuisance   nuisance -3.13249601           nuisance-4
## 75        nuisance   nuisance  0.31333973           nuisance-2
## 76        nuisance   nuisance -3.13657280           nuisance-4
## 77        nuisance   nuisance -3.13206805           nuisance-2
## 78        nuisance   nuisance  1.04446483           nuisance-0
## 79        nuisance   nuisance -0.87174272           nuisance-2
## 80        nuisance   nuisance -0.87003878           nuisance-4
## 81        nuisance   nuisance -0.86856394           nuisance-2
## 82        nuisance   nuisance  1.04446483           nuisance-4
## 83        nuisance   nuisance -0.86888867           nuisance-4
## 84        nuisance   nuisance -0.87388240           nuisance-0
## 85        nuisance   nuisance -0.86920765           nuisance-0
## 86        nuisance   nuisance -0.47165160           nuisance-2
## 87        nuisance   nuisance -0.47504671           nuisance-0
## 88        nuisance   nuisance -0.47993961           nuisance-2
## 89        nuisance   nuisance -0.47097838           nuisance-2
## 90        nuisance   nuisance -0.47561427           nuisance-0
## 91        nuisance   nuisance -0.47317794           nuisance-4
## 92        nuisance   nuisance -0.47308822           nuisance-0
## 93        nuisance   nuisance -0.47522472           nuisance-2
## 94        nuisance   nuisance  1.04446489           nuisance-4
## 95        nuisance   nuisance -0.87290175           nuisance-4
## 96        nuisance   nuisance -0.86851938           nuisance-4
## 97        nuisance   nuisance -0.87246645           nuisance-0
## 98        nuisance   nuisance -0.87011489           nuisance-0
## 99        nuisance   nuisance -0.87034705           nuisance-4
## 100       nuisance   nuisance  1.04446489           nuisance-0
## 101       nuisance   nuisance -0.86797493           nuisance-2
## 102       nuisance   nuisance  1.62018425           nuisance-2
## 103       nuisance   nuisance -0.53987700           nuisance-0
## 104       nuisance   nuisance -0.53812837           nuisance-2
## 105       nuisance   nuisance -0.53911050           nuisance-4
## 106       nuisance   nuisance  1.62018425           nuisance-4
## 107       nuisance   nuisance -0.54113456           nuisance-2
## 108       nuisance   nuisance -0.54136947           nuisance-0
## 109       nuisance   nuisance -0.54074860           nuisance-0
## 110       nuisance   nuisance  1.16189437           nuisance-0
## 111       nuisance   nuisance -0.77565661           nuisance-4
## 112       nuisance   nuisance -0.77465872           nuisance-4
## 113       nuisance   nuisance -0.77182314           nuisance-4
## 114       nuisance   nuisance -0.77544821           nuisance-0
## 115       nuisance   nuisance -0.77506250           nuisance-0
## 116       nuisance   nuisance  1.16189437           nuisance-2
## 117       nuisance   nuisance -0.77492829           nuisance-4
## 118       nuisance   nuisance  1.03774819           nuisance-4
## 119       nuisance   nuisance -0.88789825           nuisance-0
## 120       nuisance   nuisance -0.89172233           nuisance-2
## 121       nuisance   nuisance -0.88756193           nuisance-0
## 122       nuisance   nuisance -0.89178936           nuisance-0
## 123       nuisance   nuisance -0.88779413           nuisance-4
## 124       nuisance   nuisance -0.88977165           nuisance-0
## 125       nuisance   nuisance -0.88995150           nuisance-2
## 126       nuisance   nuisance  1.05409235           nuisance-4
## 127       nuisance   nuisance -0.84409535           nuisance-2
## 128       nuisance   nuisance -0.84325293           nuisance-2
## 129       nuisance   nuisance -0.84240519           nuisance-4
## 130       nuisance   nuisance  1.05409235           nuisance-2
## 131       nuisance   nuisance -0.84237854           nuisance-2
## 132       nuisance   nuisance  1.05409235           nuisance-0
## 133       nuisance   nuisance -0.84423737           nuisance-4
## 134       nuisance   nuisance -0.47628889           nuisance-2
## 135       nuisance   nuisance -0.47351358           nuisance-4
## 136       nuisance   nuisance -0.47716840           nuisance-4
## 137       nuisance   nuisance -0.47341295           nuisance-4
## 138       nuisance   nuisance -0.47749456           nuisance-2
## 139       nuisance   nuisance -0.47045207           nuisance-2
## 140       nuisance   nuisance -0.47328686           nuisance-0
## 141       nuisance   nuisance -0.47310725           nuisance-0
## 142       nuisance   nuisance -0.77487066           nuisance-0
## 143       nuisance   nuisance -0.77593536           nuisance-0
## 144       nuisance   nuisance -0.77311553           nuisance-4
## 145       nuisance   nuisance -0.77404505           nuisance-0
## 146       nuisance   nuisance  1.16189469           nuisance-4
## 147       nuisance   nuisance -0.77437658           nuisance-4
## 148       nuisance   nuisance  1.16189469           nuisance-4
## 149       nuisance   nuisance -0.77523560           nuisance-2
## 150       nuisance   nuisance -1.57307784           nuisance-2
## 151       nuisance   nuisance -1.56974499           nuisance-0
## 152       nuisance   nuisance -1.57315765           nuisance-2
## 153       nuisance   nuisance -1.56978522           nuisance-0
## 154       nuisance   nuisance -1.56840948           nuisance-0
## 155       nuisance   nuisance -1.57202942           nuisance-2
## 156       nuisance   nuisance  0.61100983           nuisance-2
## 157       nuisance   nuisance -1.57197236           nuisance-0
## 158       nuisance   nuisance  1.62018469           nuisance-0
## 159       nuisance   nuisance -0.53882141           nuisance-4
## 160       nuisance   nuisance -0.53977563           nuisance-4
## 161       nuisance   nuisance -0.53975396           nuisance-2
## 162       nuisance   nuisance  1.62018469           nuisance-2
## 163       nuisance   nuisance -0.53982328           nuisance-2
## 164       nuisance   nuisance -0.54143992           nuisance-0
## 165       nuisance   nuisance -0.54075518           nuisance-4
## 166       nuisance   nuisance -0.33508200           nuisance-2
## 167       nuisance   nuisance -0.33417201           nuisance-2
## 168       nuisance   nuisance -0.33281200           nuisance-2
## 169       nuisance   nuisance -0.33019816           nuisance-2
## 170       nuisance   nuisance -0.33032781           nuisance-2
## 171       nuisance   nuisance -0.33468161           nuisance-4
## 172       nuisance   nuisance -0.33712458           nuisance-0
## 173       nuisance   nuisance -0.33226180           nuisance-4
## 174       nuisance   nuisance  1.33333239           nuisance-2
## 175       nuisance   nuisance -0.66655966           nuisance-4
## 176       nuisance   nuisance -0.66619500           nuisance-4
## 177       nuisance   nuisance -0.66721934           nuisance-2
## 178       nuisance   nuisance  1.33333239           nuisance-4
## 179       nuisance   nuisance -0.66408853           nuisance-0
## 180       nuisance   nuisance -0.66733554           nuisance-0
## 181       nuisance   nuisance -0.66859910           nuisance-4
## 182       nuisance   nuisance -0.33127179           nuisance-0
## 183       nuisance   nuisance -0.33448191           nuisance-0
## 184       nuisance   nuisance -0.33798713           nuisance-4
## 185       nuisance   nuisance -0.32896747           nuisance-2
## 186       nuisance   nuisance -0.33099022           nuisance-2
## 187       nuisance   nuisance -0.33379241           nuisance-4
## 188       nuisance   nuisance -0.33825787           nuisance-2
## 189       nuisance   nuisance -0.33090418           nuisance-0
##     onset_code_byrep
## 1         nuisance-2
## 2         nuisance-0
## 3         nuisance-4
## 4         nuisance-2
## 5         nuisance-2
## 6         nuisance-4
## 7         nuisance-4
## 8         nuisance-4
## 9         nuisance-0
## 10        nuisance-0
## 11        nuisance-4
## 12        nuisance-4
## 13        nuisance-2
## 14        nuisance-4
## 15        nuisance-2
## 16        nuisance-0
## 17        nuisance-2
## 18        nuisance-0
## 19        nuisance-2
## 20        nuisance-2
## 21        nuisance-0
## 22        nuisance-4
## 23        nuisance-4
## 24        nuisance-2
## 25        nuisance-0
## 26        nuisance-2
## 27        nuisance-4
## 28        nuisance-2
## 29        nuisance-2
## 30        nuisance-0
## 31        nuisance-2
## 32        nuisance-4
## 33        nuisance-4
## 34        nuisance-2
## 35        nuisance-2
## 36        nuisance-0
## 37        nuisance-4
## 38        nuisance-0
## 39        nuisance-0
## 40        nuisance-0
## 41        nuisance-4
## 42        nuisance-4
## 43        nuisance-2
## 44        nuisance-4
## 45        nuisance-2
## 46        nuisance-4
## 47        nuisance-2
## 48        nuisance-0
## 49        nuisance-0
## 50        nuisance-4
## 51        nuisance-4
## 52        nuisance-4
## 53        nuisance-4
## 54        nuisance-2
## 55        nuisance-0
## 56        nuisance-2
## 57        nuisance-2
## 58        nuisance-0
## 59        nuisance-0
## 60        nuisance-4
## 61        nuisance-0
## 62        nuisance-0
## 63        nuisance-0
## 64        nuisance-2
## 65        nuisance-0
## 66        nuisance-0
## 67        nuisance-2
## 68        nuisance-0
## 69        nuisance-0
## 70        nuisance-0
## 71        nuisance-0
## 72        nuisance-2
## 73        nuisance-2
## 74        nuisance-4
## 75        nuisance-2
## 76        nuisance-4
## 77        nuisance-2
## 78        nuisance-0
## 79        nuisance-2
## 80        nuisance-4
## 81        nuisance-2
## 82        nuisance-4
## 83        nuisance-4
## 84        nuisance-0
## 85        nuisance-0
## 86        nuisance-2
## 87        nuisance-0
## 88        nuisance-2
## 89        nuisance-2
## 90        nuisance-0
## 91        nuisance-4
## 92        nuisance-0
## 93        nuisance-2
## 94        nuisance-4
## 95        nuisance-4
## 96        nuisance-4
## 97        nuisance-0
## 98        nuisance-0
## 99        nuisance-4
## 100       nuisance-0
## 101       nuisance-2
## 102       nuisance-2
## 103       nuisance-0
## 104       nuisance-2
## 105       nuisance-4
## 106       nuisance-4
## 107       nuisance-2
## 108       nuisance-0
## 109       nuisance-0
## 110       nuisance-0
## 111       nuisance-4
## 112       nuisance-4
## 113       nuisance-4
## 114       nuisance-0
## 115       nuisance-0
## 116       nuisance-2
## 117       nuisance-4
## 118       nuisance-4
## 119       nuisance-0
## 120       nuisance-2
## 121       nuisance-0
## 122       nuisance-0
## 123       nuisance-4
## 124       nuisance-0
## 125       nuisance-2
## 126       nuisance-4
## 127       nuisance-2
## 128       nuisance-2
## 129       nuisance-4
## 130       nuisance-2
## 131       nuisance-2
## 132       nuisance-0
## 133       nuisance-4
## 134       nuisance-2
## 135       nuisance-4
## 136       nuisance-4
## 137       nuisance-4
## 138       nuisance-2
## 139       nuisance-2
## 140       nuisance-0
## 141       nuisance-0
## 142       nuisance-0
## 143       nuisance-0
## 144       nuisance-4
## 145       nuisance-0
## 146       nuisance-4
## 147       nuisance-4
## 148       nuisance-4
## 149       nuisance-2
## 150       nuisance-2
## 151       nuisance-0
## 152       nuisance-2
## 153       nuisance-0
## 154       nuisance-0
## 155       nuisance-2
## 156       nuisance-2
## 157       nuisance-0
## 158       nuisance-0
## 159       nuisance-4
## 160       nuisance-4
## 161       nuisance-2
## 162       nuisance-2
## 163       nuisance-2
## 164       nuisance-0
## 165       nuisance-4
## 166       nuisance-2
## 167       nuisance-2
## 168       nuisance-2
## 169       nuisance-2
## 170       nuisance-2
## 171       nuisance-4
## 172       nuisance-0
## 173       nuisance-4
## 174       nuisance-2
## 175       nuisance-4
## 176       nuisance-4
## 177       nuisance-2
## 178       nuisance-4
## 179       nuisance-0
## 180       nuisance-0
## 181       nuisance-4
## 182       nuisance-0
## 183       nuisance-0
## 184       nuisance-4
## 185       nuisance-2
## 186       nuisance-2
## 187       nuisance-4
## 188       nuisance-2
## 189       nuisance-0
with(dt %>% filter(shock_and_post != 0), table(cond, mem_conditions))
##          mem_conditions
## cond      CR FA itemhit_lo  M nuisance sourcehit sourcemiss_hi
##   foil     0  0          0  0       63         0             0
##   indoor   0  0          0  0       71         0             0
##   outdoor  0  0          0  0       55         0             0
dj %>% filter(shock_and_post != 0)
##  [1] X.x                  run                  trial               
##  [4] onset                duration             shockCond           
##  [7] shockTrial           target               associate           
## [10] resp                 acc                  accSpec             
## [13] respRT               subid                remove              
## [16] anxious              happy                safe                
## [19] stressed             life_stress          sleep               
## [22] cond_orig            shock_and_post       conf                
## [25] onset_adj            mem_conditions       obj_conditions      
## [28] onset_code           rt_z                 mem_conditions_byrep
## [31] onset_code_byrep     img_type             X.y                 
## [34] index                group                condition           
## [37] category             X0                   X2                  
## [40] X4                   X6                   X8                  
## [43] X10                  X12                  avg_logit           
## [46] imgType             
## <0 rows> (or 0-length row.names)
dj = dj %>% filter(shock_and_post == 0)
dim(dj)
## [1] 1865   46
subids_lowtrials = dj %>% 
  group_by(group, subid) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), fill = list(count= 0)) %>%
  filter(count < 6) %>% 
  pull(subid) %>% unique()
subids_lowtrials
## factor(0)
## 42 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap173
contrasts(dj$group) = c(1,-1); contrasts(dj$group)
##         [,1]
## control    1
## stress    -1
with(dj, table(subid))
## subid
## ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ap110 ap111 ap113 
##    62    79    21    72    81    72    50    26    38    20    59    59 
## ap114 ap115 ap116 ap117 ap118 ap119 ap120 ap121 ap122 ap150 ap152 ap153 
##    50    56    72    67    36    78    62     7    33    35    40    31 
## ap154 ap155 ap157 ap158 ap159 ap160 ap161 ap162 ap163 ap164 ap165 ap166 
##    39    22    40    11    49    43    27    19    74    12    53    58 
## ap167 ap169 ap170 ap171 ap172 ap173 
##    34    64    55    32    19     8
subids_rm
## [1] "ap168" "ap174"
d_avg = dj %>% filter(!subid %in% subids_lowtrials) %>%
  group_by(group, subid) %>%
  summarise(mean=mean(avg_logit))

bartlett.test(mean ~ group, data=d_avg)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean by group
## Bartlett's K-squared = 2.6769, df = 1, p-value = 0.1018
t.test(mean ~ group, data=d_avg, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  mean by group
## t = 1.5914, df = 40, p-value = 0.1194
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.09784085  0.82253259
## sample estimates:
## mean in group control  mean in group stress 
##              1.146385              0.784039
d_avg %>% group_by(group) %>% summarise(mean(mean), n())
## # A tibble: 2 x 3
##     group `mean(mean)` `n()`
##    <fctr>        <dbl> <int>
## 1 control     1.146385    22
## 2  stress     0.784039    20
boxplot(mean ~ group, data=d_avg)

ggplot(d_avg, aes(x=group, y=mean, color=group)) +
  geom_boxplot() + geom_jitter() +
  scale_color_manual(values = palette) +
  xlab('') + ylab('Logit')

t.test(d_avg %>% filter(group == 'control') %>% pull(mean), mu = 0)
## 
##  One Sample t-test
## 
## data:  d_avg %>% filter(group == "control") %>% pull(mean)
## t = 9.0135, df = 21, p-value = 1.156e-08
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.8818883 1.4108815
## sample estimates:
## mean of x 
##  1.146385
t.test(d_avg %>% filter(group == 'stress') %>% pull(mean), mu = 0)
## 
##  One Sample t-test
## 
## data:  d_avg %>% filter(group == "stress") %>% pull(mean)
## t = 4.0485, df = 19, p-value = 0.0006859
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.3786987 1.1893793
## sample estimates:
## mean of x 
##  0.784039

S8) Inferior parietal reinstatement

Load in data

d = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_place_byreps_avg_46810_filtartloc_scalewithinrun.csv')

subids_rm = c('ap168') # bad localizer classification

# filter d to just good subjs, and only OLD items
d = d %>%
  filter(!subid %in% subids_rm) %>%
  filter(cond %in% c('sourcemiss_hi', 'sourcehit', 'M', 'itemhit_lo')) %>%
  mutate(pcorr = factor(ifelse(cond == "sourcehit", 1, 0)),
         vtc_logit = avg_logit)

dt %>% filter(shock_and_post == 2) # one subj w/consecutive shocks - trial needs to be removed (though mem_condition == 'nuisance')
##      X run trial    onset duration shockCond shockTrial target associate
## 1 6677   5    13 141.3117  11.5306    threat          1   WHIP     ocean
##      resp acc accSpec respRT subid       group remove anxious happy safe
## 1 outdoor   H   HO_Hi 0.1927 ap160 stress-fmri     NA       4     3    6
##   stressed life_stress sleep cond_orig    cond reps shock_and_post conf
## 1        5           3   4.5      TO_4 outdoor    4              2   Hi
##   onset_adj mem_conditions obj_conditions onset_code      rt_z
## 1  129.3117       nuisance       nuisance   nuisance -3.136573
##   mem_conditions_byrep onset_code_byrep
## 1           nuisance-4       nuisance-4
# Merge w/other behavioral info
d = dt %>%
  mutate(onset=onset_adj, img_type=cond) %>% 
  dplyr::select(-group, -reps, -cond) %>%
  right_join(d, by=c('subid', 'run', 'onset')) %>%
  mutate(subid = factor(subid), imgType = factor(img_type))
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
dim(d)
## [1] 6781   50
d = d %>% filter(shock_and_post == 0)
dim(d)
## [1] 6780   50
# Read in hipp BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-hippocampus.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-hippocampus.csv')
# dim(roi_lh); dim(roi_rh)

# Take timepoints of interest for old trials, and collapse across hemispheres
roi_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(hipp_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# Read in hipp tail BOLD
roi_tail_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-hippocampus-tail.csv')
roi_tail_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-hippocampus-tail.csv')

# Take timepoints of interest for old trials, and collapse across hemispheres
roi_tail_f = bind_rows("lh" = roi_tail_lh, "rh" = roi_tail_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(hipp_tail_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# Read in angular BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-DefaultA_IPL.csv')
angular_lh_f = roi_lh %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, run, onset) %>%
  summarise(angular_lh_sig = mean_(mean_activity)) %>% ungroup()

# Read in RSP BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-DefaultC_Rsp.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-DefaultC_Rsp.csv')

# Take timepoints of interest for old trials, and collapse across hemispheres
rsp_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(rsp_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# Read in CCN BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-frontoparietal.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-frontoparietal.csv')
# dim(roi_lh); dim(roi_rh)

# Take timepoints of interest for old trials, and collapse across hemispheres
CCN_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(CCN_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# also, just for LH
CCN_lh_f = roi_lh %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, run, onset) %>%
  summarise(CCN_lh_sig = mean_(mean_activity)) %>% ungroup()

# Read in DAN BOLD
roi_lh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_lh-dorsalattn.csv')
roi_rh = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/extractraw_AP_mvpa_raw_rh-dorsalattn.csv')
# dim(roi_lh); dim(roi_rh)

# Take timepoints of interest for old trials, and collapse across hemispheres
DAN_f = bind_rows("lh" = roi_lh, "rh" = roi_rh, .id = "hemi") %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, hemi, run, onset) %>%
  summarise(mean_activity = mean_(mean_activity)) %>%
  group_by(subid, run, onset) %>%
  summarise(DAN_sig = mean_(mean_activity)) %>% ungroup()
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# also, just for LH
DAN_lh_f = roi_lh %>%
  filter(condition %in% c('sourcemiss_hi', 'sourcehit', 'itemhit_lo', 'M'),
    time %in% c(4,6,8,10)) %>%
  group_by(subid, run, onset) %>%
  summarise(DAN_lh_sig = mean_(mean_activity)) %>% ungroup()

# Other reinstatement
d_infpar = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_inferiorparietal_place_byreps_avg_46810_filtartloc_scalewithinrun.csv') %>%
  filter(!subid %in% subids_rm) %>%
  filter(cond %in% c('sourcemiss_hi', 'sourcehit', 'M', 'itemhit_lo')) %>%
  mutate(ang_logit = avg_logit) %>%
  dplyr::select(subid, run, onset, ang_logit)

d_hipp = read.csv('/Users/sgagnon/Dropbox/Stanford/Presentations/AP/mvpa_logit_bilat-hippocampus_place_byreps_avg_46810_filtartloc_scalewithinrun.csv') %>%
  filter(!subid %in% subids_rm) %>%
  filter(cond %in% c('sourcemiss_hi', 'sourcehit', 'M', 'itemhit_lo')) %>%
  mutate(pcorr = factor(ifelse(cond == "sourcehit", 1, 0)),
         hipp_logit = avg_logit) %>%
  dplyr::select(subid, run, onset, hipp_logit)

# Merge w/VTC classifier evidence
dm_ip = d %>%
  left_join(roi_f, by=c('subid', 'run', 'onset')) %>%
  left_join(roi_tail_f, by=c('subid', 'run', 'onset')) %>%
  left_join(DAN_f, by=c('subid', 'run', 'onset')) %>%
  left_join(CCN_f, by=c('subid', 'run', 'onset')) %>%
  left_join(rsp_f, by=c('subid', 'run', 'onset')) %>%
  left_join(angular_lh_f, by=c('subid', 'run', 'onset')) %>%
  left_join(DAN_lh_f, by=c('subid', 'run', 'onset')) %>%
  left_join(CCN_lh_f, by=c('subid', 'run', 'onset')) %>%
  left_join(d_infpar, by=c('subid', 'run', 'onset')) %>%
  left_join(d_hipp, by=c('subid', 'run', 'onset')) %>%
  group_by(subid) %>%
  mutate(ang_logit_z = zscore(ang_logit),
         vtc_logit_z = zscore(vtc_logit),
         hipp_logit_z = zscore(hipp_logit),
         CCN_sig_z = zscore(CCN_sig),
         rsp_sig_z = zscore(rsp_sig),
         DAN_sig_z = zscore(DAN_sig),
         angular_lh_sig_z = zscore(angular_lh_sig),
         CCN_lh_sig_z = zscore(CCN_lh_sig),
         DAN_lh_sig_z = zscore(DAN_lh_sig),
         hipp_sig_z = zscore(hipp_sig),
         hipp_tail_sig_z = zscore(hipp_tail_sig),
         reps = factor(reps),
         hipp_quintile = ntile(hipp_sig, 5),
         rsp_quintile = ntile(rsp_sig, 5),
         CCN_quintile = ntile(CCN_sig, 5),
         DAN_quintile = ntile(DAN_sig, 5),
         angular_lh_sig_quintile = ntile(angular_lh_sig, 5),
         CCN_lh_quintile = ntile(CCN_lh_sig, 5),
         DAN_lh_quintile = ntile(DAN_lh_sig, 5),
         hipp_tail_quintile = ntile(hipp_tail_sig, 5),
         vtc_quintile = ntile(vtc_logit, 5),
         hipp_logit_quintile = ntile(hipp_logit, 5),
         ang_quintile = ntile(ang_logit, 5)) %>%
  ungroup() %>%
  mutate(subid = factor(subid),
         cond = factor(cond),
         condition = factor(condition))
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector

## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector
dim(dm_ip) #just hipp: 6623  
## [1] 6780   82
with(dm_ip, table(subid, reps))
##        reps
## subid    2  4
##   ap100 76 78
##   ap101 83 82
##   ap102 80 79
##   ap103 83 79
##   ap104 82 83
##   ap105 81 81
##   ap107 79 82
##   ap108 72 74
##   ap109 81 77
##   ap110 82 81
##   ap111 82 84
##   ap113 83 83
##   ap114 81 81
##   ap115 78 82
##   ap116 80 82
##   ap117 84 80
##   ap118 83 81
##   ap119 80 81
##   ap120 79 76
##   ap121 84 81
##   ap122 84 82
##   ap150 77 78
##   ap152 73 78
##   ap153 77 75
##   ap154 67 78
##   ap155 69 66
##   ap157 77 79
##   ap158 84 83
##   ap159 81 81
##   ap160 66 64
##   ap161 81 79
##   ap162 75 80
##   ap163 83 78
##   ap164 79 79
##   ap165 75 81
##   ap166 79 79
##   ap167 76 77
##   ap169 77 79
##   ap170 81 81
##   ap171 81 81
##   ap172 80 76
##   ap173 73 74
##   ap174 77 80
str(dm_ip)
## Classes 'tbl_df', 'tbl' and 'data.frame':    6780 obs. of  82 variables:
##  $ X.x                    : int  0 2 3 4 5 7 8 11 14 15 ...
##  $ run                    : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ trial                  : int  1 3 4 5 6 8 9 12 15 16 ...
##  $ onset                  : num  0.0191 19.8642 29.3132 40.6786 50.4701 ...
##  $ duration               : num  10.67 9.42 11.34 9.76 9.12 ...
##  $ shockCond              : Factor w/ 2 levels "safe","threat": 1 1 1 1 1 1 1 1 1 1 ...
##  $ shockTrial             : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ target                 : Factor w/ 252 levels "ACCORDIAN","ACROBAT",..: 15 238 116 114 183 224 87 102 192 191 ...
##  $ associate              : Factor w/ 241 levels "\002\002","\002",..: 68 237 126 61 175 233 53 118 173 84 ...
##  $ resp                   : Factor w/ 4 levels "foil","indoor",..: 2 2 4 4 4 1 1 1 4 2 ...
##  $ acc                    : Factor w/ 6 levels "CR","FA","H",..: 6 3 3 3 3 4 4 4 3 3 ...
##  $ accSpec                : Factor w/ 15 levels "CR","FAI_Hi",..: 14 6 8 8 8 10 10 10 8 6 ...
##  $ respRT                 : num  2.11 1.68 1.73 1.37 2.15 ...
##  $ subid                  : Factor w/ 43 levels "ap100","ap101",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ remove                 : logi  NA NA NA NA NA NA ...
##  $ anxious                : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ happy                  : int  2 2 2 2 2 2 2 2 2 2 ...
##  $ safe                   : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ stressed               : int  3 3 3 3 3 3 3 3 3 3 ...
##  $ life_stress            : int  4 4 4 4 4 4 4 4 4 4 ...
##  $ sleep                  : num  4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 4.5 ...
##  $ cond_orig              : Factor w/ 5 levels "F_0","TI_2","TI_4",..: 5 2 4 4 5 3 2 4 5 2 ...
##  $ shock_and_post         : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ conf                   : Factor w/ 3 levels "Hi","Lo","N": 1 1 1 1 1 3 3 3 1 1 ...
##  $ onset_adj              : num  0.0191 19.8642 29.3132 40.6786 50.4701 ...
##  $ mem_conditions         : Factor w/ 7 levels "CR","FA","itemhit_lo",..: 7 6 6 6 6 4 4 4 6 6 ...
##  $ obj_conditions         : Factor w/ 3 levels "new","nuisance",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ onset_code             : Factor w/ 6 levels "CR","FA","itemhit",..: 3 6 6 6 6 4 4 4 6 6 ...
##  $ rt_z                   : num  -1.2039 -0.746 -0.6739 -1.2235 -0.0194 ...
##  $ mem_conditions_byrep   : Factor w/ 13 levels "CR-0","FA-0",..: 13 10 10 10 11 6 5 5 11 10 ...
##  $ onset_code_byrep       : Factor w/ 11 levels "CR-0","FA-0",..: 4 10 10 10 11 6 5 5 11 10 ...
##  $ img_type               : Factor w/ 3 levels "foil","indoor",..: 3 2 3 3 3 2 2 3 3 2 ...
##  $ X.y                    : int  2 8 11 14 17 23 26 35 44 47 ...
##  $ index                  : int  2 8 11 14 17 23 26 35 44 47 ...
##  $ group                  : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ condition              : Factor w/ 8 levels "itemhit_lo-2",..: 8 5 5 5 6 4 3 3 6 5 ...
##  $ category               : Factor w/ 1 level "place": 1 1 1 1 1 1 1 1 1 1 ...
##  $ X0                     : num  -6.635 -9.265 6.804 8.431 0.203 ...
##  $ X2                     : num  -6.32 -4.39 7.22 3.92 -3.54 ...
##  $ X4                     : num  -1.49 5.79 4.22 1.8 -2.75 ...
##  $ X6                     : num  2.59 5.69 -3.03 3.7 3.74 ...
##  $ X8                     : num  -1.03 8.65 -1.68 -1.28 -2.28 ...
##  $ X10                    : num  -0.642 6.486 8.468 -0.23 -9.405 ...
##  $ X12                    : num  -1.1 6.64 11.49 -3.55 -5.64 ...
##  $ avg_logit              : num  -0.145 6.655 1.996 0.998 -2.673 ...
##  $ cond                   : Factor w/ 4 levels "itemhit_lo","M",..: 4 3 3 3 3 2 2 2 3 3 ...
##  $ reps                   : Factor w/ 2 levels "2","4": 2 1 1 1 2 2 1 1 2 1 ...
##  $ pcorr                  : Factor w/ 2 levels "0","1": 1 2 2 2 2 1 1 1 2 2 ...
##  $ vtc_logit              : num  -0.145 6.655 1.996 0.998 -2.673 ...
##  $ imgType                : Factor w/ 2 levels "indoor","outdoor": 2 1 2 2 2 1 1 2 2 1 ...
##  $ hipp_sig               : num  0.2754 0.4613 -0.1955 -0.0154 -0.14 ...
##  $ hipp_tail_sig          : num  0.11449 0.49252 -0.00556 -0.06895 -0.13196 ...
##  $ DAN_sig                : num  0.175 0.658 0.225 -0.262 -0.395 ...
##  $ CCN_sig                : num  0.367 0.4107 0.0192 -0.1273 -0.2068 ...
##  $ rsp_sig                : num  0.3053 1.5956 -0.0991 -0.19 -0.5123 ...
##  $ angular_lh_sig         : num  0.20058 0.85916 -0.09532 0.00574 -0.04293 ...
##  $ DAN_lh_sig             : num  0.212 0.585 0.183 -0.233 -0.383 ...
##  $ CCN_lh_sig             : num  0.3687 0.2566 0.1633 -0.1271 -0.0121 ...
##  $ ang_logit              : num  -2.066 5.935 0.249 -3.792 -6.49 ...
##  $ hipp_logit             : num  -2.553 1.418 -1.783 -2.571 -0.555 ...
##  $ ang_logit_z            : num  -0.474 1.931 0.222 -0.993 -1.804 ...
##  $ vtc_logit_z            : num  -0.148 1.895 0.495 0.195 -0.907 ...
##  $ hipp_logit_z           : num  -0.491 1.406 -0.123 -0.499 0.464 ...
##  $ CCN_sig_z              : num  0.6436 0.7336 -0.0722 -0.3738 -0.5374 ...
##  $ rsp_sig_z              : num  0.209 2.071 -0.375 -0.506 -0.971 ...
##  $ DAN_sig_z              : num  0.391 1.606 0.516 -0.711 -1.046 ...
##  $ angular_lh_sig_z       : num  0.177 1.513 -0.423 -0.218 -0.317 ...
##  $ CCN_lh_sig_z           : num  0.537 0.31 0.121 -0.468 -0.235 ...
##  $ DAN_lh_sig_z           : num  0.437 1.389 0.363 -0.7 -1.082 ...
##  $ hipp_sig_z             : num  0.537 0.967 -0.552 -0.135 -0.424 ...
##  $ hipp_tail_sig_z        : num  0.167 1.146 -0.143 -0.307 -0.47 ...
##  $ hipp_quintile          : int  4 5 2 3 2 1 4 1 3 4 ...
##  $ rsp_quintile           : int  3 5 2 2 1 1 4 1 3 3 ...
##  $ CCN_quintile           : int  4 4 3 2 2 1 5 1 3 3 ...
##  $ DAN_quintile           : int  4 5 4 2 1 1 4 1 2 4 ...
##  $ angular_lh_sig_quintile: int  3 5 2 3 2 1 2 1 4 4 ...
##  $ CCN_lh_quintile        : int  4 3 3 2 3 1 5 1 4 3 ...
##  $ DAN_lh_quintile        : int  4 5 4 2 1 1 4 1 3 4 ...
##  $ hipp_tail_quintile     : int  3 5 3 2 2 1 4 1 3 5 ...
##  $ vtc_quintile           : int  3 5 4 3 1 2 2 1 5 4 ...
##  $ hipp_logit_quintile    : int  2 5 3 2 4 2 5 3 1 3 ...
##  $ ang_quintile           : int  2 5 4 1 1 1 4 2 4 5 ...
# set up contrasts
contrasts(dm_ip$pcorr) = c(-1,1); contrasts(dm_ip$pcorr)
##   [,1]
## 0   -1
## 1    1
contrasts(dm_ip$reps) = c(-1,1); contrasts(dm_ip$reps)
##   [,1]
## 2   -1
## 4    1
contrasts(dm_ip$group) = c(1,-1); contrasts(dm_ip$group)
##         [,1]
## control    1
## stress    -1
contrasts(dm_ip$shockCond) = c(1,-1); contrasts(dm_ip$shockCond)
##        [,1]
## safe      1
## threat   -1

Trial-wise analysis counts/group:

dm_ip %>% group_by(subid, group) %>% summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    21

HC assoc hits: infparietal reinstatement ~ group

subids_lowtrials = dm_ip %>% 
  filter(cond == 'sourcehit') %>%
  group_by(group, subid) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), fill = list(count= 0)) %>%
  filter(count < 6) %>% 
  pull(subid) %>% unique()
subids_lowtrials
## factor(0)
## 43 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap174
d_avg = dm_ip %>% filter(!subid %in% subids_lowtrials) %>%
  filter(cond == 'sourcehit') %>%
  group_by(group, subid) %>%
  summarise(mean=mean(ang_logit))
with(d_avg, table(group))
## group
## control  stress 
##      22      21
# diff between groups?
bartlett.test(mean ~ group, data=d_avg)
## 
##  Bartlett test of homogeneity of variances
## 
## data:  mean by group
## Bartlett's K-squared = 1.2052, df = 1, p-value = 0.2723
t.test(mean ~ group, data=d_avg, var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  mean by group
## t = 0.89075, df = 41, p-value = 0.3783
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.2509866  0.6471018
## sample estimates:
## mean in group control  mean in group stress 
##             0.3410088             0.1429512
d_avg %>% group_by(group) %>% summarise(mean(mean), n())
## # A tibble: 2 x 3
##     group `mean(mean)` `n()`
##    <fctr>        <dbl> <int>
## 1 control    0.3410088    22
## 2  stress    0.1429512    21
t.test(d_avg %>% filter(group == 'control') %>% pull(mean), mu = 0)
## 
##  One Sample t-test
## 
## data:  d_avg %>% filter(group == "control") %>% pull(mean)
## t = 2.5122, df = 21, p-value = 0.02024
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  0.05871977 0.62329777
## sample estimates:
## mean of x 
## 0.3410088
t.test(d_avg %>% filter(group == 'stress') %>% pull(mean), mu = 0)
## 
##  One Sample t-test
## 
## data:  d_avg %>% filter(group == "stress") %>% pull(mean)
## t = 0.80435, df = 20, p-value = 0.4307
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.2277736  0.5136759
## sample estimates:
## mean of x 
## 0.1429512

HC accuracy mediation

dat = dtest %>% 
  filter(subj_status == 'old',
         reps > 0, # old item
         conf == 'Hi') %>%
  group_by(subid, group) %>%
  summarise(mean_acc = mean(acc_num), sum=sum(acc_num), count=n()) %>%
  ungroup() %>%
  complete(nesting(subid, group), fill = list(mean_acc=0,
                                                    count=0))
dat
## # A tibble: 47 x 5
##     subid   group  mean_acc   sum count
##    <fctr>  <fctr>     <dbl> <dbl> <dbl>
##  1  ap100 control 0.8725490    89   102
##  2  ap101 control 0.9375000   105   112
##  3  ap102 control 0.7010309    68    97
##  4  ap103 control 0.8968254   113   126
##  5  ap104 control 0.9130435   147   161
##  6  ap105 control 0.8623188   119   138
##  7  ap106 control 0.5087719    29    57
##  8  ap107 control 0.8802817   125   142
##  9  ap108 control 0.7073171    29    41
## 10  ap109 control 0.6489362    61    94
## # ... with 37 more rows
# filter out subjs who don't have more than 5 "old" responses to old cues
dim(dat) # all subjs included
## [1] 47  5
dat %>% filter(count < 6) 
## # A tibble: 1 x 5
##    subid  group mean_acc   sum count
##   <fctr> <fctr>    <dbl> <dbl> <dbl>
## 1  ap151 stress      0.6     3     5
rm_subids = dat %>% filter(count < 6) %>% pull(subid) %>% unique(); rm_subids
## [1] ap151
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
rm_subids # ap151
## [1] ap151
## 47 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap106 ap107 ap108 ... ap174
dat = dat %>% filter(!subid %in% rm_subids)
subids_lowtrials = dm_ip %>% 
  filter(cond == 'sourcehit') %>%
  group_by(group, subid) %>% 
  summarise(count = n()) %>% 
  ungroup() %>%
  complete(nesting(subid, group), fill = list(count= 0)) %>%
  filter(count < 6) %>% 
  pull(subid) %>% unique()
subids_lowtrials
## factor(0)
## 43 Levels: ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ... ap174
with(dm_ip %>% filter(cond == 'sourcehit'), table(subid))
## subid
## ap100 ap101 ap102 ap103 ap104 ap105 ap107 ap108 ap109 ap110 ap111 ap113 
##    87   102    66   111   146   117   122    28    58    20    73    75 
## ap114 ap115 ap116 ap117 ap118 ap119 ap120 ap121 ap122 ap150 ap152 ap153 
##   101    77   144    84    62   112    71    33    95    66    40    31 
## ap154 ap155 ap157 ap158 ap159 ap160 ap161 ap162 ap163 ap164 ap165 ap166 
##    42    38    51    11    50    51    27    41   107    81    64    71 
## ap167 ap169 ap170 ap171 ap172 ap173 ap174 
##    38    69    74    33    20     8    84
d_avg =  dm_ip %>% 
  filter(cond == 'sourcehit') %>%
  filter(!subid %in% subids_lowtrials) %>%
  group_by(group, subid) %>%
  summarise(mean=mean(ang_logit))
dim(d_avg)
## [1] 43  3
d_avg
## Source: local data frame [43 x 3]
## Groups: group [?]
## 
## # A tibble: 43 x 3
##      group  subid       mean
##     <fctr> <fctr>      <dbl>
##  1 control  ap100  0.2261302
##  2 control  ap101  0.4469116
##  3 control  ap102  0.8927461
##  4 control  ap103 -0.7333308
##  5 control  ap104  0.1633124
##  6 control  ap105  0.3764084
##  7 control  ap107  0.2016958
##  8 control  ap108 -0.2507325
##  9 control  ap109 -0.2083484
## 10 control  ap110  0.3040365
## # ... with 33 more rows
vtc = d_avg %>% mutate(mean_logit = mean) %>% dplyr::select(-mean)
dim(vtc)
## [1] 43  3
vtc %>% group_by(subid, group) %>% summarise(n()) %>% group_by(group) %>% summarise(n())
## # A tibble: 2 x 2
##     group `n()`
##    <fctr> <int>
## 1 control    22
## 2  stress    21
roi = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/pe_sourcehit-cr_zstat1_peak1_5mm_sphere_masked.nii.csv')
roi = roi %>% filter(cond %in% c('sourcehit', 'CR')) %>%
  mutate(cond = factor(cond)) %>% 
  dplyr::select(subid, group, cond, value) %>%  # calc diff score
  spread(key = cond, value=value) %>%
  mutate(diff = sourcehit - CR) %>%
  right_join(vtc, by = c('subid', 'group')) %>%
  left_join(dat, by = c('subid', 'group')) %>%
  mutate(diff_orig = diff,
         diff = scale(diff),
         mean_logit = scale(mean_logit),
          mean_acc = as.numeric(scale(car::logit(mean_acc))))
## Warning in right_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factors with different levels, coercing to character vector
## Warning in left_join_impl(x, y, by$x, by$y, suffix$x, suffix$y): joining
## factor and character vector, coercing into character vector
dim(roi)
## [1] 43 10
str(roi)
## 'data.frame':    43 obs. of  10 variables:
##  $ subid     : chr  "ap100" "ap101" "ap102" "ap103" ...
##  $ group     : Factor w/ 2 levels "control","stress": 1 1 1 1 1 1 1 1 1 1 ...
##  $ CR        : num  -396 320 107 -519 -416 ...
##  $ sourcehit : num  379.9 990.6 891.5 90.7 -99.2 ...
##  $ diff      : num [1:43, 1] 0.947 0.673 0.968 0.515 -0.246 ...
##   ..- attr(*, "scaled:center")= num 411
##   ..- attr(*, "scaled:scale")= num 385
##  $ mean_logit: num [1:43, 1] -0.025 0.279 0.892 -1.345 -0.111 ...
##   ..- attr(*, "scaled:center")= num 0.244
##   ..- attr(*, "scaled:scale")= num 0.727
##  $ mean_acc  : num  0.44 1.43 -0.913 0.742 0.98 ...
##  $ sum       : num  89 105 68 113 147 119 125 29 61 20 ...
##  $ count     : num  102 112 97 126 161 138 142 41 94 21 ...
##  $ diff_orig : num  776 671 784 610 317 ...
contrasts(roi$group) = c(1,-1)

model.t = lm(mean_acc ~ diff, data=roi); summary(model.t) 
## 
## Call:
## lm(formula = mean_acc ~ diff, data = roi)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.28067 -0.48665  0.01898  0.55006  1.87160 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 2.545e-17  1.339e-01   0.000 1.000000    
## diff        4.971e-01  1.355e-01   3.668 0.000696 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8782 on 41 degrees of freedom
## Multiple R-squared:  0.2471, Adjusted R-squared:  0.2287 
## F-statistic: 13.46 on 1 and 41 DF,  p-value: 0.0006961
model.m = lm(mean_logit ~ diff, data=roi); summary(model.m)
## 
## Call:
## lm(formula = mean_logit ~ diff, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.5013 -0.6140 -0.1443  0.5246  2.2846 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)  
## (Intercept) -2.314e-17  1.470e-01   0.000   1.0000  
## diff         3.041e-01  1.488e-01   2.044   0.0474 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.9642 on 41 degrees of freedom
## Multiple R-squared:  0.09246,    Adjusted R-squared:  0.07033 
## F-statistic: 4.177 on 1 and 41 DF,  p-value: 0.04743
model.y = lm(mean_acc ~ mean_logit + diff, data=roi); summary(model.y)
## 
## Call:
## lm(formula = mean_acc ~ mean_logit + diff, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.2776 -0.5048  0.0094  0.5413  1.8692 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)   
## (Intercept) 2.594e-17  1.356e-01   0.000   1.0000   
## mean_logit  2.121e-02  1.440e-01   0.147   0.8836   
## diff        4.907e-01  1.440e-01   3.408   0.0015 **
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.8889 on 40 degrees of freedom
## Multiple R-squared:  0.2475, Adjusted R-squared:  0.2099 
## F-statistic: 6.579 on 2 and 40 DF,  p-value: 0.003388
model.other = lm(mean_acc ~ mean_logit, data=roi); summary(model.other)
## 
## Call:
## lm(formula = mean_acc ~ mean_logit, data = roi)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.1276 -0.8065 -0.1195  0.7939  2.0194 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.693e-17  1.521e-01   0.000    1.000
## mean_logit  1.704e-01  1.539e-01   1.107    0.275
## 
## Residual standard error: 0.9973 on 41 degrees of freedom
## Multiple R-squared:  0.02904,    Adjusted R-squared:  0.005354 
## F-statistic: 1.226 on 1 and 41 DF,  p-value: 0.2746
## Bootstrapping Confidence Interval (BCa and Percentile)
boot.med <- function(data, indices){
    data <-data[indices,]   #this does the random resampling of rows

    reg1 <- lm(mean_logit ~ diff, data=data)
    reg2 <- lm(mean_acc ~ mean_logit + diff, data=data)
    
    a <- coefficients(reg1)["diff"] #the a path coefficient
    b <- coefficients(reg2)["mean_logit"]   #the b path coefficient
    a*b                         #returns the product of a*b
}

medboot<-boot(data=roi, statistic = boot.med, R=5000)   
mean(medboot$t)
## [1] 0.002536981
quantile(medboot$t, c(0.025, 0.975))
##        2.5%       97.5% 
## -0.10593348  0.09848875
# [1] 0.001264906
#        2.5%       97.5%
# -0.11376327  0.09313285

Other analyses

Is PPA activity reduced for item hits relative to source hits?

# dat = read.csv('/Volumes/group/awagner/sgagnon/AP/analysis/ap_memory_raw/group/roi/pe_ppa_scene_limitvox.csv')
# dat = dat %>% filter(cond %in% c('sourcehit', 
#                                  'itemhit_lo')) %>%
#   mutate(cond = factor(cond))
# str(dat)
# 
# subids_lowtrials = dm %>% 
#   filter(cond %in% c('itemhit_lo', 'sourcehit')) %>%
#   mutate(cond = factor(cond)) %>%
#   group_by(group, cond, subid) %>% 
#   summarise(count = n()) %>% 
#   ungroup() %>%
#   complete(nesting(subid, group), cond, 
#            fill = list(count= 0)) %>%
#   filter(count < 6) %>% 
#   pull(subid) %>% unique()
# print(subids_lowtrials)
# 
# dat = dat %>% filter(!subid %in% subids_lowtrials) %>%
#   mutate(subid = factor(subid))
# with(dat, table(subid))
# head(dat)
# 
# contrasts(dat$group) = c(1,-1); contrasts(dat$group)
# contrasts(dat$cond) = c(-1,1); contrasts(dat$cond)
# summary(lmer(value ~ group * cond + (1|subid), data=dat)) # rand slope, not enough obs
# 
# bartlett.test(value ~ group, data=dat %>% filter(cond == 'sourcehit'))
# t.test(value ~ group, data=dat %>% filter(cond == 'sourcehit'), var.equal=TRUE)
# t.test(value ~ group, data=dat %>% filter(cond == 'itemhit_lo'), var.equal=TRUE)
# 
# dat %>% filter(cond == 'itemhit_lo') %>% pull(value)
# t.test(dat %>% filter(cond == 'itemhit_lo') %>% pull(value), mu=0)
# 
# dat %>% group_by(group, cond) %>% summarise(mean = mean(value), 
#                                             se = std.error(value), n())